查看: 1025|回復: 4

[問題] 跟隨還是有些問題,請教!

[複製鏈接]

10

主題

123

帖子

2萬

金錢

巴列斯

Rank: 10Rank: 10Rank: 10

威望
5
精華
0
貢獻
0
鑽石
0
閱讀權限
60
積分
20850
在線時間
193 小時
相冊
0
日誌
0
好友
2
發表於 2024-3-11 21:01 | 顯示全部樓層 |閱讀模式
QQ图片20240311210528.png


        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。

以上,求大大幫忙看看咋搞~




上一篇︰我開小黑盒
下一篇︰抽檔程式 刪檔一問

1

主題

587

帖子

1萬

金錢

巴列斯

Rank: 10Rank: 10Rank: 10

威望
0
精華
0
貢獻
0
鑽石
0
閱讀權限
60
積分
17701
在線時間
299 小時
相冊
0
日誌
0
好友
0
發表於 2024-3-11 22:39 | 顯示全部樓層
AttackMon觸發條件 沒有先認主人

或者是 targets 寫成共用了

紅茶
聯絡方式
LINE: lineageapp
回復 支持 反對

使用道具 舉報

10

主題

123

帖子

2萬

金錢

巴列斯

Rank: 10Rank: 10Rank: 10

威望
5
精華
0
貢獻
0
鑽石
0
閱讀權限
60
積分
20850
在線時間
193 小時
相冊
0
日誌
0
好友
2
 樓主| 發表於 2024-3-12 11:55 | 顯示全部樓層
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[4];
                int[] locCopy;
                int[] dirFront = new int[5];
                boolean serchMap[][] = new boolean[locCenter * 2 + 1][locCenter * 2 + 1];
                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[j][locCenter + i] = true;
                                serchMap[j][locCenter - i] = 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[0] - locCenter == 0 && locNext[1] - locCenter == 0) {
                                // 最短经路が见つかった场合:邻
                                return firstCource;
                        }
                        if (locNext[0] > 29 || locNext[1] > 29 || locNext[0] <= -1 || locNext[1] <= -1){
//                                pc.setTeleportX(targetg.getX());
//                                pc.setTeleportY(targetg.getY());
//                                pc.setTeleportMapId((short) targetg.getMapId());
//                                pc.setTeleportHeading(pc.getHeading());
//                                teleportation(pc);
                                return 1;
                        }
                        if (serchMap[locNext[0]][locNext[1]]) {
                                int tmpX = locNext[0] + diff_x;
                                int tmpY = locNext[1] + 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[4];
                                        System.arraycopy(locNext, 0, locCopy, 0, 4);
                                        locCopy[2] = firstCource;
                                        locCopy[3] = firstCource;
                                        queueSerch.add(locCopy);
                                }
                                serchMap[locNext[0]][locNext[1]] = false;
                        }
                }
                locBace = null;


                // 最短经路を探索
                while (queueSerch.size() > 0) {
                        locBace = queueSerch.removeFirst();
                        _getFront(dirFront, locBace[2]);
                        for (i = 4; i >= 0; i--) {
                                System.arraycopy(locBace, 0, locNext, 0, 4);
                                _moveLocation(locNext, dirFront);
                                if (locNext[0] - locCenter == 0 && locNext[1] - locCenter == 0) {
                                        return locNext[3];
                                }
                                if (serchMap[locNext[0]][locNext[1]]) {
                                        int tmpX = locNext[0] + diff_x;
                                        int tmpY = locNext[1] + 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[4];
                                                System.arraycopy(locNext, 0, locCopy, 0, 4);
                                                locCopy[2] = dirFront;
                                                queueSerch.add(locCopy);
                                        }
                                        serchMap[locNext[0]][locNext[1]] = false;
                                }
                        }
                        locBace = null;
                }
                return -1; // 目标までの经路がない场合
        }
       
        private void _moveLocation(int[] ary, int dir) {
                ary[0] += DIR_TABLE[dir][0];
                ary[1] += DIR_TABLE[dir][1];
                ary[2] = dir;
        }
       
        private void _getFront(int[] ary, int d) {
                switch (d) {
                case 1:
                        ary[4] = 2;
                        ary[3] = 0;
                        ary[2] = 1;
                        ary[1] = 3;
                        ary[0] = 7;
                        break;
                case 2:
                        ary[4] = 2;
                        ary[3] = 4;
                        ary[2] = 0;
                        ary[1] = 1;
                        ary[0] = 3;
                        break;
                case 3:
                        ary[4] = 2;
                        ary[3] = 4;
                        ary[2] = 1;
                        ary[1] = 3;
                        ary[0] = 5;
                        break;
                case 4:
                        ary[4] = 2;
                        ary[3] = 4;
                        ary[2] = 6;
                        ary[1] = 3;
                        ary[0] = 5;
                        break;
                case 5:
                        ary[4] = 4;
                        ary[3] = 6;
                        ary[2] = 3;
                        ary[1] = 5;
                        ary[0] = 7;
                        break;
                case 6:
                        ary[4] = 4;
                        ary[3] = 6;
                        ary[2] = 0;
                        ary[1] = 5;
                        ary[0] = 7;
                        break;
                case 7:
                        ary[4] = 6;
                        ary[3] = 0;
                        ary[2] = 1;
                        ary[1] = 5;
                        ary[0] = 7;
                        break;
                case 0:
                        ary[4] = 2;
                        ary[3] = 6;
                        ary[2] = 0;
                        ary[1] = 1;
                        ary[0] = 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[h];
                        int h3 = _heading3[h];
                        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[dir];
                locy += HEADING_TABLE_Y[dir];
                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);
                }
        }
}


回復 支持 反對

使用道具 舉報

10

主題

123

帖子

2萬

金錢

巴列斯

Rank: 10Rank: 10Rank: 10

威望
5
精華
0
貢獻
0
鑽石
0
閱讀權限
60
積分
20850
在線時間
193 小時
相冊
0
日誌
0
好友
2
 樓主| 發表於 2024-3-12 11:56 | 顯示全部樓層
yasioukon 發表於 2024-3-11 22:39
AttackMon觸發條件 沒有先認主人

或者是 targets 寫成共用了

麻煩大大幫忙看看

回復 支持 反對

使用道具 舉報

14

主題

142

帖子

3236

金錢

暗殺軍王.史雷佛

Rank: 8Rank: 8

威望
0
精華
0
貢獻
0
鑽石
0
閱讀權限
45
積分
3378
在線時間
31 小時
相冊
0
日誌
0
好友
3
QQ
發表於 2024-3-18 01:21 | 顯示全部樓層
zouzouge 發表於 2024-3-12 11:56
麻煩大大幫忙看看

这么多代码看起来很伤眼睛的。


把 targets 按主人分类出来就可以了,new 一个 hateList 出来比较好,AI的优化是一件很复杂的事情,测试时间越长,就会发现越多问题,才能改得越精细。


http://starway.freebbs.tw/index.php
回復 支持 反對

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊會員

本版積分規則

天堂私服列表

45客服

Archiver| 45天堂私服論壇   分享到微博! 分享到臉書! 分享到噗浪! 分享到維特! 分享到Google+! 分享到LINE!

45天堂私服發佈站 ©    天堂私服架設教學  提供最新天堂私服最新資訊

流量最高、品質最好、服務最優、玩家首選、最新天堂私服資訊,都在45天堂私服發佈站.    免責聲明

Sitetag
line客服聯繫
掃一掃二碼
Line客服聯繫
24H專人回覆
返回頂部 返回列表