跟隨還是有些問題,請教!
private void AttackMon(final L1PcInstance pc, final L1Character targets) {
try {
if (!pc.IsFollow()) {
pc.sendPackets(new S_SystemMessage("停止跟随"));
return;
}
if (pc.glanceCheck(targets.getX(), targets.getY()) &&
!targets.isDead()){
pc.attackTarget(targets);
} else {
target = SearchTarget(pc);
}
} catch (Exception e) {
_log.error(e.getLocalizedMessage(), e);
}
}
以上這一段有問題,四個角色在同一個地圖,兩個主人,兩個打手,如果主人1打了其中一個怪物,打手1和打手2就會去攻擊同一個怪物,感覺是pc.attackTarget(targets);這句沒寫對,或者PC(也就是打手)不是唯一的,讓整個地圖里的打手都去攻擊targets。
以上,求大大幫忙看看咋搞~
AttackMon觸發條件 沒有先認主人
或者是 targets 寫成共用了 yasioukon 發表於 2024-3-11 22:39
AttackMon觸發條件 沒有先認主人
或者是 targets 寫成共用了
package com.add.NewAuto;
import java.util.LinkedList;
import java.util.Timer;
import java.util.TimerTask;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.lineage.config.ThreadPoolSet;
import com.lineage.server.clientpackets.AcceleratorChecker;
import com.lineage.server.datatables.SkillsTable;
import com.lineage.server.datatables.lock.CharSkillReading;
import com.lineage.server.model.L1Character;
import com.lineage.server.model.L1Location;
import com.lineage.server.model.L1Object;
import com.lineage.server.model.L1Trade;
import com.lineage.server.model.Instance.L1DollInstance;
import com.lineage.server.model.Instance.L1MonsterInstance;
import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.map.L1Map;
import com.lineage.server.model.map.L1WorldMap;
import com.lineage.server.model.skill.L1SkillId;
import com.lineage.server.model.skill.L1SkillUse;
import com.lineage.server.serverpackets.S_CharVisualUpdate;
import com.lineage.server.serverpackets.S_MapID;
import com.lineage.server.serverpackets.S_MoveCharPacket;
import com.lineage.server.serverpackets.S_NPCPack_Doll;
import com.lineage.server.serverpackets.S_OtherCharPacks;
import com.lineage.server.serverpackets.S_OwnCharPack;
import com.lineage.server.serverpackets.S_PacketBoxWindShackle;
import com.lineage.server.serverpackets.S_Paralysis;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.templates.L1Skills;
import com.lineage.server.thread.PcAutoThreadPool;
import com.lineage.server.types.Point;
import com.lineage.server.world.World;
/**
* 跟随系统
* @author Manly
*
*/
public class FollowPc extends TimerTask {
private static Log _log = LogFactory.getLog(FollowPc.class);
public static L1Character target = null;
private L1PcInstance pc = null;
private int update = 0;
private Timer _timeHandler = new Timer(true);
public FollowPc(L1PcInstance user) {
pc = user;
}
protected static int _heading2[] = { 7, 0, 1, 2, 3, 4, 5, 6 };
protected static int _heading3[] = { 1, 2, 3, 4, 5, 6, 7, 0 };
protected int[][] DIR_TABLE = { { 0, -1 }, { 1, -1 },
{ 1, 0 }, { 1, 1 }, { 0, 1 }, { -1, 1 }, { -1, 0 },
{ -1, -1 } };
public void begin() {
_timeHandler.schedule(this, 250, 250);
PcAutoThreadPool.get().execute(this);
}
public void stop() {
try {
if (this.cancel()) {
_timeHandler.purge();
}
target = null;
update = 0;
pc.setFollowId(0);
pc.setFollow(false);
pc.setFollowMode(0);
pc.sendPackets(new S_SystemMessage("已设定停止或跟随目标异常 跟随停止"));
} catch (Exception e) {
_log.error(e.getLocalizedMessage(), e);
}
}
@Override
public void run() {
try {
if (pc == null
|| pc.isDead()
|| pc.getCurrentHp() <= 0
|| !pc.IsFollow()
|| pc.getNetConnection() == null) {
stop();
pc.sendPackets(new S_SystemMessage("停止跟随3"));
} else {
L1Object targetM = World.get().findObject(pc.getFollowId());
if (targetM == null) {
stop();
pc.sendPackets(new S_SystemMessage("停止跟随4"));
return;
} else {
if (targetM instanceof L1PcInstance) {
final L1PcInstance targetPc = (L1PcInstance) targetM;
if (targetPc.getBeFollowId() == 0) {
stop();
pc.sendPackets(new S_SystemMessage("停止跟随5"));
return;
}
}
}
if (pc.getFollowMode() == 1) {
L1Object target2 = World.get().findObject(pc.getFollowId());
final L1Character targets = target;
final L1PcInstance targetzPc = (L1PcInstance) target2;
L1Object obj = World.get().findObject(targetzPc.getAttackId());
// if (obj instanceof L1MonsterInstance) {
// final L1PcInstance targetPc = (L1PcInstance) target2;
if (target != null) {
if (target.isDead()) {
target = null;
}
// if (targetzPc.isSafetyZone() && !pc.isSafetyZone()) {
// target = null;
// pc.setTeleportX(targetzPc.getX());
// pc.setTeleportY(targetzPc.getY());
// pc.setTeleportMapId((short) targetzPc.getMapId());
// pc.setTeleportHeading(pc.getHeading());
// teleportation(pc);
// MoveCha(pc , targetzPc);
// return;
// }
if (target != null) {
if (target instanceof L1MonsterInstance) {
L1MonsterInstance mob = (L1MonsterInstance) target;
if (mob.getHiddenStatus() == 1 ||
mob.getHiddenStatus() == 2 ||
mob.getHiddenStatus() == 3) {
target = null;
}
}
}
if (target != null) {
int Ranged = 1;
if (pc.getWeapon() != null) {
Ranged = pc.getWeapon().getItem().getRange();
if (Ranged == -1 || Ranged > 2) {
Ranged = 8;
}
}
final int location =
this.pc.getLocation().getTileLineDistance
(targets.getLocation());
if (location <= Ranged &&
this.pc.glanceCheck(target.getX(), target.getY())) {
AttackMon(this.pc , this.target);
int SPEED = pc.getAcceleratorChecker().getRightInterval
(AcceleratorChecker.ACT_TYPE.ATTACK);
if (SPEED < ThreadPoolSet.ATTACK_SPEED) {
SPEED = ThreadPoolSet.ATTACK_SPEED;
}
SPEED = (SPEED * ThreadPoolSet.REXT) / 100;
Thread.sleep(SPEED);
} else {
// if (pc.getLocation().getTileLineDistance(targetzPc.getLocation()) > 11) {
// target = null;
// pc.targetClear();
// pc.allTargetClear();
// target = SearchTarget(pc);
// }
Move(this.pc, targets);
int SPEED = pc.getAcceleratorChecker().getRightInterval
(AcceleratorChecker.ACT_TYPE.MOVE);
if (SPEED < ThreadPoolSet.WALK_SPEED) {
SPEED = ThreadPoolSet.WALK_SPEED;
}
SPEED = (SPEED * ThreadPoolSet.REXT) / 100;
Thread.sleep(SPEED);
}
}
} else {
target = SearchTarget(this.pc);
if (target == null) {
L1Object target1 = World.get().findObject(this.pc.getFollowId());
if (target1 != null) {
if (target1 instanceof L1PcInstance) {
final L1PcInstance targetPc = (L1PcInstance) target1;
MoveCha(this.pc , targetPc);
}
} else {
stop();
pc.sendPackets(new S_SystemMessage("停止跟随1"));
}
}
}
} else {
FollowCha(pc);
}
}
} catch (Exception e) {
// stop();
// pc.sendPackets(new S_SystemMessage("停止跟随2"));
_log.error(e.getLocalizedMessage(), e);
}
}
private void FollowCha(final L1PcInstance pc) {
L1Object target1 = World.get().findObject(pc.getFollowId());
if (target1 != null) {
if (target1 instanceof L1PcInstance) {
final L1PcInstance targetPc = (L1PcInstance) target1;
if (targetPc.getMapId() != 613 && targetPc.getMapId() != 53 && targetPc.getMapId() != 780 && targetPc.getMapId() != 781 && targetPc.getMapId() != 5168 && targetPc.getMapId() != 305) {
if (pc.getLocation().getTileLineDistance(targetPc.getLocation()) > 10 ||
pc.getMapId() != targetPc.getMapId()) {
pc.setTeleportX(targetPc.getX());
pc.setTeleportY(targetPc.getY());
pc.setTeleportMapId((short) targetPc.getMapId());
pc.setTeleportHeading(pc.getHeading());
teleportation(pc);
return;
}
}
if (targetPc.getMapId() == 613 || targetPc.getMapId() == 53 || targetPc.getMapId() == 780 || targetPc.getMapId() == 781 || targetPc.getMapId() == 5168 || targetPc.getMapId() == 305) {
if (pc.getLocation().getTileLineDistance(targetPc.getLocation()) > 10 &&
pc.getMapId() == targetPc.getMapId()) {
pc.setTeleportX(targetPc.getX());
pc.setTeleportY(targetPc.getY());
pc.setTeleportMapId((short) targetPc.getMapId());
pc.setTeleportHeading(pc.getHeading());
teleportation(pc);
return;
}
}
MoveCha(pc , targetPc);
if(CharSkillReading.get().spellCheck(pc.getId(), 35)){
double FollowPcHp = targetPc.getMaxHp() * 0.75;
if (targetPc.getCurrentHp() < FollowPcHp) {
L1Skills skill = SkillsTable.get().getTemplate(35);
new L1SkillUse().handleCommands
(pc, 35, targetPc.getId(),
targetPc.getX(), targetPc.getY(),
skill.getBuffDuration(), 0);
}
}
}
}
}
private L1Character SearchTarget(L1PcInstance pc) {
try {
if (pc.hasSkillEffect(L1SkillId.STATUS_CURSE_PARALYZED)) {
return null;
}
if (pc.hasSkillEffect(L1SkillId.STATUS_POISON_PARALYZED)) {
return null;
}
if (pc.hasSkillEffect(L1SkillId.STATUS_FREEZE)) {
return null;
}
L1Object target1 = World.get().findObject(pc.getFollowId());
if (target1 != null) {
if (target1 instanceof L1PcInstance) {
final L1PcInstance targetPc = (L1PcInstance) target1;
L1Object objg = World.get().findObject(targetPc.getAttackId());
if (targetPc.getMapId() != 613 && targetPc.getMapId() != 53 && targetPc.getMapId() != 780 && targetPc.getMapId() != 781 && targetPc.getMapId() != 5168 && targetPc.getMapId() != 305) {
if (pc.getLocation().getTileLineDistance(targetPc.getLocation()) > 10 ||
pc.getMapId() != targetPc.getMapId()) {
pc.setTeleportX(targetPc.getX());
pc.setTeleportY(targetPc.getY());
pc.setTeleportMapId((short) targetPc.getMapId());
pc.setTeleportHeading(pc.getHeading());
teleportation(pc);
MoveCha(pc , targetPc);
return null;
}
}
if (targetPc.getMapId() == 613 || targetPc.getMapId() == 53 || targetPc.getMapId() == 780 || targetPc.getMapId() == 781 || targetPc.getMapId() == 5168 || targetPc.getMapId() == 305) {
if (pc.getLocation().getTileLineDistance(targetPc.getLocation()) > 10 &&
pc.getMapId() == targetPc.getMapId()) {
pc.setTeleportX(targetPc.getX());
pc.setTeleportY(targetPc.getY());
pc.setTeleportMapId((short) targetPc.getMapId());
pc.setTeleportHeading(pc.getHeading());
teleportation(pc);
MoveCha(pc , targetPc);
return null;
}
}
L1Object obj = World.get().findObject(targetPc.getAttackId());
if (obj instanceof L1MonsterInstance) {
final L1MonsterInstance mob = (L1MonsterInstance) obj;
if (mob.isDead()) {
return null;
}
if (mob.getHiddenStatus() == 1 ||
mob.getHiddenStatus() == 2 ||
mob.getHiddenStatus() == 3) {
return null;
}
if (pc.glanceCheck(mob.getX(), mob.getY())){
return mob;
}
}
}
}
return null;
} catch (Exception e) {
_log.error(e.getLocalizedMessage(), e);
return null;
}
}
private void AttackMon(final L1PcInstance pc, final L1Character targets) {
L1Object target1 = World.get().findObject(pc.getFollowId());
final L1PcInstance targetPc = (L1PcInstance) target1;
L1Object targetsnow = World.get().findObject(targetPc.getAttackId());
try {
if (!pc.IsFollow()) {
pc.sendPackets(new S_SystemMessage("停止跟随"));
return;
}
if (pc.glanceCheck(targets.getX(), targets.getY()) &&
// pc.getLocation().getTileLineDistance(targetPc.getLocation()) < 6 &&
!targets.isDead()){
// targets.onAction(this.pc);
// this.pc._hateList.add(target, 0);
this.pc.attackTarget(targets);
// targets.attack(pc, this);
} else {
// target = null;
// pc.targetClear();
target = SearchTarget(this.pc);
// MoveCha(pc , targetPc);
}
} catch (Exception e) {
_log.error(e.getLocalizedMessage(), e);
}
}
private void MoveCha(L1PcInstance pc , L1Character targets) {
try {
if (!pc.IsFollow()) {
pc.sendPackets(new S_SystemMessage("停止跟随"));
return;
}
int location =
pc.getLocation().getTileLineDistance
(targets.getLocation());
int Ranged = 2;
if (location > Ranged ) {
int dir = moveDirection(pc,targets.getX(), targets.getY());
if (dir >= 0) {
setDirectionMove(pc, dir);
}
}
} catch (Exception e) {
_log.error(e.getLocalizedMessage(), e);
}
}
private void Move(L1PcInstance pc , L1Character targets) {
L1Object target1 = World.get().findObject(pc.getFollowId());
final L1PcInstance targetPc = (L1PcInstance) target1;
try {
if (!pc.IsFollow()) {
pc.sendPackets(new S_SystemMessage("停止跟随"));
return;
}
int location =
pc.getLocation().getTileLineDistance
(targets.getLocation());
int Ranged = 1;
if (pc.getWeapon() != null) {
Ranged = pc.getWeapon().getItem().getRange();
if (Ranged == -1 || Ranged > 2) {
Ranged = 8;
}
}
if (location <= Ranged &&
pc.glanceCheck(targets.getX(), targets.getY())) {
AttackMon(this.pc, targets);
} else {
int dir = moveDirection(pc,targets.getX(), targets.getY());
setDirectionMove(pc, dir);
}
} catch (Exception e) {
_log.error(e.getLocalizedMessage(), e);
}
}
private static void teleportation(L1PcInstance pc) {
try {
if (pc == null) {
return;
}
if (pc.getOnlineStatus() == 0) {
return;
}
if (pc.getNetConnection().getIp() == null) {
return;
}
if (pc.getNetConnection() == null) {
return;
}
if (pc.isDead()) {
return;
}
if (pc.isTeleport()) {
return;
}
if (pc.getTradeID() != 0) {
L1Trade trade = new L1Trade();
trade.tradeCancel(pc);
}
// 解除旧座标障碍宣告
pc.getMap().setPassable(pc.getLocation(), true);
short mapId = pc.getTeleportMapId();
int x = pc.getTeleportX();
int y = pc.getTeleportY();
int head = pc.getTeleportHeading();
L1Map map = L1WorldMap.get().getMap(mapId);
if ((!map.isInMap(x, y)) && (!pc.isGm()&& (pc.isGm()))) {
x = pc.getX();
y = pc.getY();
mapId = pc.getMapId();
}
World.get().moveVisibleObject(pc, mapId);
pc.setLocation(x, y, mapId);//设置角色新座标
pc.setHeading(head);
pc.setOleLocX(x);
pc.setOleLocY(y);
boolean isUnderwater = pc.getMap().isUnderwater();
pc.sendPackets(new S_MapID(pc, pc.getMapId(), isUnderwater));
if ((!pc.isGhost()) && (!pc.isGmInvis()) && (!pc.isInvisble())) {
pc.broadcastPacketAll(new S_OtherCharPacks(pc));
}
pc.sendPackets(new S_OwnCharPack(pc));
pc.removeAllKnownObjects();
pc.updateObject();
pc.sendPackets(new S_CharVisualUpdate(pc));
pc.killSkillEffectTimer(32);// 冥想术
pc.setCallClanId(0);
if (!pc.getDolls().isEmpty()) {
// 主人身边随机座标取回
L1Location loc = pc.getLocation().randomLocation(3, false);
int nx = loc.getX();
int ny = loc.getY();
Object[] dolls = pc.getDolls().values().toArray();
for (Object obj : dolls) {
L1DollInstance doll = (L1DollInstance) obj;
teleport(doll, nx, ny, mapId, head);
pc.sendPackets(new S_NPCPack_Doll(doll, pc));
// 设置副本编号
doll.set_showId(pc.get_showId());
}
}
if (pc.hasSkillEffect(167)) {// 风之枷锁
pc.sendPackets(new S_PacketBoxWindShackle
(pc.getId(), pc.getSkillEffectTimeSec(167)));
}
// 新增座标障碍宣告
if (!pc.isGmInvis()) {// 排除GM隐身
pc.getMap().setPassable(pc.getLocation(), false);
}
pc.getPetModel();// 恢复宠物目前模式
} catch (Exception e) {
// 解除传送锁定
pc.sendPackets(new S_Paralysis(S_Paralysis.TYPE_TELEPORT_UNLOCK, false));
_log.error(e.getLocalizedMessage(), e);
} finally {
// 解除传送锁定
pc.sendPackets(new S_Paralysis(S_Paralysis.TYPE_TELEPORT_UNLOCK, false));
}
}
/**
* 追踪方向返回
*/
private int moveDirection(L1PcInstance pc, int targetsx, int targetsy) { // 目标点X目标点Y
return moveDirection
(pc, targetsx, targetsy,
pc.getLocation().getLineDistance
(new Point(targetsx, targetsy)));
}
private int courceRange = 20;
private int moveDirection(L1PcInstance pc, int targetsx, int targetsy,
double d) {
int dir = 0;
if ((pc.hasSkillEffect(40) == true) && (d >= 2D)) {
return -1;
} else if (d > 100D) {
return -1;
} else if (d > 100) {
dir = _targetDirection
(pc.getHeading(), pc.getX(), pc.getY(), targetsx, targetsy);
dir = checkObject(pc, dir);
} else {
dir = _serchCource(pc, targetsx, targetsy);
dir = checkObject(pc, dir);
if (dir == -1) {
dir = _targetDirection
(pc.getHeading(), pc.getX(), pc.getY(), targetsx, targetsy);
dir = checkObject(pc, dir);
}
}
return dir;
}
protected int _serchCource(L1PcInstance pc, int x, int y){
int i;
int locCenter = courceRange + 1;
int diff_x = x - locCenter; // Xの实际のロケーションとの差
int diff_y = y - locCenter; // Yの实际のロケーションとの差
int[] locBace = { pc.getX() - diff_x, pc.getY() - diff_y, 0, 0 }; // X
// Y
// 方向
// 初期方向
int[] locNext = new int;
int[] locCopy;
int[] dirFront = new int;
boolean serchMap[][] = new boolean;
LinkedList<int[]> queueSerch = new LinkedList<int[]>();
// 探索用マップの设定
for (int j = courceRange * 2 + 1; j > 0; j--) {
for (i = courceRange - Math.abs(locCenter - j); i >= 0; i--) {
serchMap = true;
serchMap = true;
}
}
// 初期方向の设置
int[] firstCource = { 2, 4, 6, 0, 1, 3, 5, 7 };
for (i = 0; i < 8; i++) {
System.arraycopy(locBace, 0, locNext, 0, 4);
_moveLocation(locNext, firstCource);
L1Object targetg = World.get().findObject(pc.getFollowId());
final L1PcInstance targetPc = (L1PcInstance) targetg;
if (locNext - locCenter == 0 && locNext - locCenter == 0) {
// 最短经路が见つかった场合:邻
return firstCource;
}
if (locNext > 29 || locNext > 29 || locNext <= -1 || locNext <= -1){
// pc.setTeleportX(targetg.getX());
// pc.setTeleportY(targetg.getY());
// pc.setTeleportMapId((short) targetg.getMapId());
// pc.setTeleportHeading(pc.getHeading());
// teleportation(pc);
return 1;
}
if (serchMap]]) {
int tmpX = locNext + diff_x;
int tmpY = locNext + diff_y;
boolean found = false;
switch(i) {
case 0:
found = pc.getMap().isPassable(tmpX, tmpY + 1, i, pc);
break;
case 1:
found = pc.getMap().isPassable(tmpX - 1, tmpY + 1, i, pc);
break;
case 2:
found = pc.getMap().isPassable(tmpX - 1, tmpY, i, pc);
break;
case 3:
found = pc.getMap().isPassable(tmpX - 1, tmpY - 1, i, pc);
break;
case 4:
found = pc.getMap().isPassable(tmpX, tmpY - 1, i, pc);
break;
case 5:
found = pc.getMap().isPassable(tmpX + 1, tmpY - 1, i, pc);
break;
case 6:
found = pc.getMap().isPassable(tmpX + 1, tmpY, i, pc);
break;
case 7:
found = pc.getMap().isPassable(tmpX + 1, tmpY + 1, i, pc);
break;
}
if (found) {// 移动经路があった场合
locCopy = new int;
System.arraycopy(locNext, 0, locCopy, 0, 4);
locCopy = firstCource;
locCopy = firstCource;
queueSerch.add(locCopy);
}
serchMap]] = false;
}
}
locBace = null;
// 最短经路を探索
while (queueSerch.size() > 0) {
locBace = queueSerch.removeFirst();
_getFront(dirFront, locBace);
for (i = 4; i >= 0; i--) {
System.arraycopy(locBace, 0, locNext, 0, 4);
_moveLocation(locNext, dirFront);
if (locNext - locCenter == 0 && locNext - locCenter == 0) {
return locNext;
}
if (serchMap]]) {
int tmpX = locNext + diff_x;
int tmpY = locNext + diff_y;
boolean found = false;
switch (i) {
case 0:
found = pc.getMap().isPassable(tmpX, tmpY + 1, i, pc);
break;
case 1:
found = pc.getMap().isPassable(tmpX - 1, tmpY + 1, i, pc);
break;
case 2:
found = pc.getMap().isPassable(tmpX - 1, tmpY, i, pc);
break;
case 3:
found = pc.getMap().isPassable(tmpX - 1, tmpY - 1, i, pc);
break;
case 4:
found = pc.getMap().isPassable(tmpX, tmpY - 1, i, pc);
break;
}
if (found) {// 移动经路があった场合
locCopy = new int;
System.arraycopy(locNext, 0, locCopy, 0, 4);
locCopy = dirFront;
queueSerch.add(locCopy);
}
serchMap]] = false;
}
}
locBace = null;
}
return -1; // 目标までの经路がない场合
}
private void _moveLocation(int[] ary, int dir) {
ary += DIR_TABLE;
ary += DIR_TABLE;
ary = dir;
}
private void _getFront(int[] ary, int d) {
switch (d) {
case 1:
ary = 2;
ary = 0;
ary = 1;
ary = 3;
ary = 7;
break;
case 2:
ary = 2;
ary = 4;
ary = 0;
ary = 1;
ary = 3;
break;
case 3:
ary = 2;
ary = 4;
ary = 1;
ary = 3;
ary = 5;
break;
case 4:
ary = 2;
ary = 4;
ary = 6;
ary = 3;
ary = 5;
break;
case 5:
ary = 4;
ary = 6;
ary = 3;
ary = 5;
ary = 7;
break;
case 6:
ary = 4;
ary = 6;
ary = 0;
ary = 5;
ary = 7;
break;
case 7:
ary = 6;
ary = 0;
ary = 1;
ary = 5;
ary = 7;
break;
case 0:
ary = 2;
ary = 6;
ary = 0;
ary = 1;
ary = 7;
break;
}
}
/**
* 目标点方向计算
*
* @param h
* 目前面向
* @param x
* 目前X
* @param y
* 目前Y
* @param tx
* 目标X
* @param ty
* 目标Y
* @return
*/
private static int _targetDirection(int h, int x,int y, int tx, int ty) {
try {
float dis_x = Math.abs(x - tx); // X点方向距离
float dis_y = Math.abs(y - ty); // Y点方向距离
float dis = Math.max(dis_x, dis_y); // 取回2者最大质
if (dis == 0) {
return h; // 距离为0表示不须改变面向
}
int avg_x = (int) Math.floor((dis_x / dis) + 0.59f); // 上下左右がちょっと优先な丸め
int avg_y = (int) Math.floor((dis_y / dis) + 0.59f); // 上下左右がちょっと优先な丸め
int dir_x = 0;
int dir_y = 0;
if (x < tx) {
dir_x = 1;
}
if (x > tx) {
dir_x = -1;
}
if (y < ty) {
dir_y = 1;
}
if (y > ty) {
dir_y = -1;
}
if (avg_x == 0) {
dir_x = 0;
}
if (avg_y == 0) {
dir_y = 0;
}
switch (dir_x) {
case -1:
switch (dir_y) {
case -1:
return 7; // 左
case 0:
return 6; // 左下
case 1:
return 5; // 下
}
break;
case 0:
switch (dir_y) {
case -1:
return 0; // 左上
case 1:
return 4; // 右下
}
break;
case 1:
switch (dir_y) {
case -1:
return 1; // 上
case 0:
return 2; // 右上
case 1:
return 3; // 右
}
break;
}
} catch (final Exception e) {
_log.error(e.getLocalizedMessage(), e);
}
return h;
}
private int checkObject(L1PcInstance pc, int h) {
if ((h >= 0) && (h <= 7)) {
int x = pc.getX();
int y = pc.getY();
int h2 = _heading2;
int h3 = _heading3;
if (pc.getMap().isPassable(x, y, h, pc)) {
return h;
} else if (pc.getMap().isPassable(x, y, h2, pc)) {
return h2;
} else if (pc.getMap().isPassable(x, y, h3, pc)) {
return h3;
}
}
return -1;
}
protected static final byte[] HEADING_TABLE_X = {0,1, 1, 1, 0, -1, -1, -1 };
protected static final byte[] HEADING_TABLE_Y = { -1, -1, 0, 1, 1,1,0, -1 };
private void setDirectionMove(L1PcInstance pc, int dir) {
if (dir >= 0) {
int locx = pc.getX();
int locy = pc.getY();
int _mode = 0;
locx += HEADING_TABLE_X;
locy += HEADING_TABLE_Y;
pc.setHeading(dir);
// 解除旧座标障碍宣告
pc.getMap().setPassable(pc.getLocation(), true);
pc.setX(locx);
pc.setY(locy);
pc.getMap().setPassable(pc.getLocation(), false);
pc.broadcastPacketAll(new S_MoveCharPacket(pc));
pc.sendPackets(new S_MoveCharPacket(pc));
update++;
if (update > 9) {
L1Location newLocation = pc.getLocation().randomLocation(1, true);
int newX = newLocation.getX();
int newY = newLocation.getY();
pc.setTeleportX(newX);
pc.setTeleportY(newY);
pc.setTeleportMapId((short) pc.getMapId());
pc.setTeleportHeading(dir);
teleportation(pc);
update = 0;
}
}
}
private static void teleport(L1NpcInstance npc, int x,
int y,short map, int head) {
try {
World.get().moveVisibleObject(npc, map);
L1WorldMap.get().getMap(npc.getMapId()).setPassable(npc.getX(), npc.getY(), true, 2);
npc.setX(x);
npc.setY(y);
npc.setMap(map);
npc.setHeading(head);
L1WorldMap.get().getMap(npc.getMapId()).setPassable(npc.getX(), npc.getY(), false, 2);
} catch (Exception e) {
_log.error(e.getLocalizedMessage(), e);
}
}
}
yasioukon 發表於 2024-3-11 22:39
AttackMon觸發條件 沒有先認主人
或者是 targets 寫成共用了
麻煩大大幫忙看看 zouzouge 發表於 2024-3-12 11:56
麻煩大大幫忙看看
这么多代码看起来很伤眼睛的。
把 targets 按主人分类出来就可以了,new 一个 hateList 出来比较好,AI的优化是一件很复杂的事情,测试时间越长,就会发现越多问题,才能改得越精细。
頁:
[1]