Jump to content
  • 0

PHANTOM NOT ATTACK


Question

Posted

Good evening, I'm having a problem with my FakePlayers, when they are pulled into the pvp area they are not attacked ... can anyone help me? Here is the FakePlayerAi diff ...

 

/*
 * Decompiled with CFR 0_132.
 */
package phantom.ai;

import java.util.ArrayList;
import net.sf.l2j.Config;
import net.sf.l2j.commons.random.Rnd;
import net.sf.l2j.gameserver.data.SkillTable;
import net.sf.l2j.gameserver.events.TvT;
import net.sf.l2j.gameserver.geoengine.GeoEngine;
import net.sf.l2j.gameserver.model.L2Skill;
import net.sf.l2j.gameserver.model.WorldObject;
import net.sf.l2j.gameserver.model.actor.Creature;
import net.sf.l2j.gameserver.model.actor.ai.CtrlIntention;
import net.sf.l2j.gameserver.model.actor.instance.Door;
import net.sf.l2j.gameserver.model.actor.instance.Monster;
import net.sf.l2j.gameserver.model.actor.instance.Player;
import net.sf.l2j.gameserver.model.location.Location;
import net.sf.l2j.gameserver.model.location.SpawnLocation;
import net.sf.l2j.gameserver.network.serverpackets.MoveToLocation;
import net.sf.l2j.gameserver.network.serverpackets.MoveToPawn;
import net.sf.l2j.gameserver.network.serverpackets.StopMove;
import net.sf.l2j.gameserver.network.serverpackets.StopRotation;
import phantom.FakePlayer;

public abstract class FakePlayerAI {
    protected final FakePlayer _fakePlayer;
    protected volatile boolean _clientMoving;
    protected volatile boolean _clientAutoAttacking;
    private long _moveToPawnTimeout;
    protected int _clientMovingToPawnOffset;
    protected boolean _isBusyThinking = false;

    public FakePlayerAI(FakePlayer character) {
        this._fakePlayer = character;
        this.setup();
        this.applyDefaultBuffs();
    }

    public void setup() {
        this._fakePlayer.setIsRunning(true);
    }

    protected void applyDefaultBuffs() {
        for (Integer skillid : this.getBuffs()) {
            try {
                L2Skill skill = SkillTable.getInstance().getInfo(skillid, SkillTable.getInstance().getMaxLevel(skillid));
                if (skill == null) continue;
                skill.getEffects(this._fakePlayer, this._fakePlayer);
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public void setBusyThinking(boolean thinking) {
        this._isBusyThinking = thinking;
    }

    public boolean isBusyThinking() {
        return this._isBusyThinking;
    }

    protected void tryTargetRandomCreatureByTypeInRadius(Class<? extends Creature> creatureClass, int radius) {
        if (_fakePlayer.getTarget() == null) {
            ArrayList<Creature> targetList = new ArrayList<>();
            for (WorldObject target : _fakePlayer.getKnownType(WorldObject.class)) {
                if (TvT.is_started() && _fakePlayer._inEventTvT) {
                    if (target instanceof Player && !((Player)target).isDead() && !((Player)target).getAppearance().getInvisible() && ((Player)target).isInsideRadius(_fakePlayer.getX(), _fakePlayer.getY(), _fakePlayer.getZ(), 400, false, false) && ((Player)target)._inEventTvT && _fakePlayer._inEventTvT && !((Player)target)._teamNameTvT.equals(_fakePlayer._teamNameTvT)) {
                        targetList.add((Player)target);
                    }
                    if (target instanceof Player && !((Player)target).isDead() && !((Player)target).getAppearance().getInvisible() && ((Player)target).isInsideRadius(_fakePlayer.getX(), _fakePlayer.getY(), _fakePlayer.getZ(), 800, false, false) && ((Player)target)._inEventTvT && _fakePlayer._inEventTvT && !((Player)target)._teamNameTvT.equals(_fakePlayer._teamNameTvT)) {
                        targetList.add((Player)target);
                    }
                    if (target instanceof Player && !((Player)target).isDead() && !((Player)target).getAppearance().getInvisible() && ((Player)target).isInsideRadius(_fakePlayer.getX(), _fakePlayer.getY(), _fakePlayer.getZ(), 1500, false, false) && ((Player)target)._inEventTvT && _fakePlayer._inEventTvT && !((Player)target)._teamNameTvT.equals(_fakePlayer._teamNameTvT)) {
                        targetList.add((Player)target);
                    }
                    if (!(target instanceof Player) || ((Player)target).isDead() || ((Player)target).getAppearance().getInvisible() || !((Player)target).isInsideRadius(_fakePlayer.getX(), _fakePlayer.getY(), _fakePlayer.getZ(), 6000, false, false) || !((Player)target)._inEventTvT || !_fakePlayer._inEventTvT || ((Player)target)._teamNameTvT.equals(_fakePlayer._teamNameTvT))
                    targetList.add((Player)target);
                    continue;
                }
                if (target instanceof Player && !((Player)target).isDead() && !((Player)target).isPhantomAntBot() && (((Player)target).getPvpFlag() > 0 || ((Player)target).getKarma() > 0) && !((Player)target).getAppearance().getInvisible() && ((Player)target).isInsideRadius(_fakePlayer.getX(), _fakePlayer.getY(), _fakePlayer.getZ(), 400, false, false) && (_fakePlayer.getClan() != null && ((Player)target).getClan() != null || _fakePlayer.getAllyId() != 0 && ((Player)target).getAllyId() != 0)) {
                    targetList.add((Player)target);
                    continue;
                }
                if (target instanceof Player && !((Player)target).isDead() && !((Player)target).isPhantomAntBot() && (((Player)target).getPvpFlag() > 0 || ((Player)target).getKarma() > 0) && !((Player)target).getAppearance().getInvisible() && ((Player)target).isInsideRadius(_fakePlayer.getX(), _fakePlayer.getY(), _fakePlayer.getZ(), 800, false, false) && (_fakePlayer.getClan() != null && ((Player)target).getClan() != null || _fakePlayer.getAllyId() != 0 && ((Player)target).getAllyId() != 0)) {
                    targetList.add((Player)target);
                    continue;
                }
                if (target instanceof Player && !((Player)target).isDead() && !((Player)target).isPhantomAntBot() && (((Player)target).getPvpFlag() > 0 || ((Player)target).getKarma() > 0) && !((Player)target).getAppearance().getInvisible() && ((Player)target).isInsideRadius(_fakePlayer.getX(), _fakePlayer.getY(), _fakePlayer.getZ(), 2000, false, false) && (_fakePlayer.getClan() != null && ((Player)target).getClan() != null || _fakePlayer.getAllyId() != 0 && ((Player)target).getAllyId() != 0)) {
                    targetList.add((Player)target);
                    continue;
                }
                if (target instanceof Player && !((Player)target).isDead() && !((Player)target).isPhantomAntBot() && (((Player)target).getPvpFlag() > 0 || ((Player)target).getKarma() > 0) && !((Player)target).getAppearance().getInvisible() && ((Player)target).isInsideRadius(_fakePlayer.getX(), _fakePlayer.getY(), _fakePlayer.getZ(), 4000, false, false) && (_fakePlayer.getClan() != null && ((Player)target).getClan() != null || _fakePlayer.getAllyId() != 0 && ((Player)target).getAllyId() != 0)) {
                    targetList.add((Player)target);
                    continue;
                }
                if (target instanceof Monster && ((Monster)target).isInsideRadius(_fakePlayer.getX(), _fakePlayer.getY(), _fakePlayer.getZ(), 400, false, false)) {
                    targetList.add((Monster)target);
                    continue;
                }
                if (target instanceof Monster && ((Monster)target).isInsideRadius(_fakePlayer.getX(), _fakePlayer.getY(), _fakePlayer.getZ(), 800, false, false)) {
                    targetList.add((Monster)target);
                    continue;
                }
                if (target instanceof Monster && ((Monster)target).isInsideRadius(_fakePlayer.getX(), _fakePlayer.getY(), _fakePlayer.getZ(), 1500, false, false)) {
                    targetList.add((Monster)target);
                    continue;
                }
                if (target instanceof Monster && ((Monster)target).isInsideRadius(_fakePlayer.getX(), _fakePlayer.getY(), _fakePlayer.getZ(), 2000, false, false)) {
                    targetList.add((Monster)target);
                    continue;
                }
                if (!(target instanceof Monster) || !((Monster)target).isInsideRadius(_fakePlayer.getX(), _fakePlayer.getY(), _fakePlayer.getZ(), 2500, false, false))
                targetList.add((Monster)target);
            }
            if (targetList.isEmpty()) {
                this._fakePlayer.setTarget(null);
            } else {
                WorldObject target;
                int nextTargetIdx = Rnd.get(targetList.size());
                target = targetList.get(nextTargetIdx);
                this._fakePlayer.setTarget(target);
            }
        } else if (((Creature)this._fakePlayer.getTarget()).isDead() || this._fakePlayer.getTarget() instanceof Player && ((Player)this._fakePlayer.getTarget()).getPvpFlag() == 0 && ((Player)this._fakePlayer.getTarget()).getKarma() == 0 && (!TvT.is_started() || !this._fakePlayer._inEventTvT)) {
            this._fakePlayer.setTarget(null);
            if (Rnd.get(100) < Config.PHANTOM_MAGE_RANDOM_WALK) {
                this.setBusyThinking(true);
                this._fakePlayer.rndWalkMonster();
                try {
                    Thread.sleep(3000L);
                }
                catch (InterruptedException targetList) {
                    // empty catch block
                }
                this.setBusyThinking(false);
            }
        }
    }

    public void castSpell(L2Skill skill) {
        if (!this._fakePlayer.isCastingNow()) {
            if (skill.getTargetType() == L2Skill.SkillTargetType.TARGET_GROUND) {
                if (this.maybeMoveToPosition(this._fakePlayer.getCurrentSkillWorldPosition(), skill.getCastRange())) {
                    this._fakePlayer.setIsCastingNow(false);
                    return;
                }
            } else {
                if (this.checkTargetLost(this._fakePlayer.getTarget())) {
                    if (skill.isOffensive() && this._fakePlayer.getTarget() != null) {
                        this._fakePlayer.setTarget(null);
                    }
                    this._fakePlayer.setIsCastingNow(false);
                    return;
                }
                if (this._fakePlayer.getTarget() != null && this.maybeMoveToPawn(this._fakePlayer.getTarget(), skill.getCastRange())) {
                    return;
                }
                if (this._fakePlayer.isSkillDisabled(skill)) {
                    return;
                }
            }
            if (skill.getHitTime() > 50 && !skill.isSimultaneousCast()) {
                this.clientStopMoving(null);
            }
            this._fakePlayer.doCast(skill);
        } else {
            this._fakePlayer.forceAutoAttack((Creature)this._fakePlayer.getTarget());
        }
    }

    protected void castSelfSpell(L2Skill skill) {
        if (!this._fakePlayer.isCastingNow() && !this._fakePlayer.isSkillDisabled(skill)) {
            if (skill.getHitTime() > 50 && !skill.isSimultaneousCast()) {
                this.clientStopMoving(null);
            }
            this._fakePlayer.doCast(skill);
        }
    }

    protected void clientStopMoving(SpawnLocation loc) {
        if (this._fakePlayer.isMoving()) {
            this._fakePlayer.stopMove(loc);
        }
        this._clientMovingToPawnOffset = 0;
        if (this._clientMoving || loc != null) {
            this._clientMoving = false;
            this._fakePlayer.broadcastPacket(new StopMove(this._fakePlayer));
            if (loc != null) {
                this._fakePlayer.broadcastPacket(new StopRotation(this._fakePlayer.getObjectId(), loc.getHeading(), 0));
            }
        }
    }

    protected boolean checkTargetLost(WorldObject target) {
        Player victim;
        if (target instanceof Player && (victim = (Player)target).isFakeDeath()) {
            victim.stopFakeDeath(true);
            return false;
        }
        if (target == null) {
            this._fakePlayer.getAI().setIntention(CtrlIntention.ACTIVE);
            return true;
        }
        return false;
    }

    protected boolean maybeMoveToPosition(Location worldPosition, int offset) {
        if (worldPosition == null) {
            return false;
        }
        if (offset < 0) {
            return false;
        }
        if (!this._fakePlayer.isInsideRadius(worldPosition.getX(), worldPosition.getY(), (int)(offset + this._fakePlayer.getCollisionRadius()), false)) {
            if (this._fakePlayer.isMovementDisabled()) {
                return true;
            }
            int x = this._fakePlayer.getX();
            int y = this._fakePlayer.getY();
            double dx = worldPosition.getX() - x;
            double dy = worldPosition.getY() - y;
            double dist = Math.sqrt(dx * dx + dy * dy);
            double sin = dy / dist;
            double cos = dx / dist;
            this.moveTo(x += (int)((dist -= offset - 5) * cos), y += (int)(dist * sin), worldPosition.getZ());
            return true;
        }
        return false;
    }

    protected void moveToPawn(WorldObject pawn, int offset) {
        if (!this._fakePlayer.isMovementDisabled()) {
            if (offset < 10) {
                offset = 10;
            }
            boolean sendPacket = true;
            if (this._clientMoving && this._fakePlayer.getTarget() == pawn) {
                if (this._clientMovingToPawnOffset == offset) {
                    if (System.currentTimeMillis() < this._moveToPawnTimeout) {
                        return;
                    }
                    sendPacket = false;
                } else if (this._fakePlayer.isOnGeodataPath() && System.currentTimeMillis() < this._moveToPawnTimeout + 1000L) {
                    return;
                }
            }
            this._clientMoving = true;
            this._clientMovingToPawnOffset = offset;
            this._fakePlayer.setTarget(pawn);
            this._moveToPawnTimeout = System.currentTimeMillis() + 1000L;
            if (pawn == null) {
                return;
            }
            this._fakePlayer.moveToLocation(pawn.getX(), pawn.getY(), pawn.getZ(), offset);
            if (!this._fakePlayer.isMoving()) {
                return;
            }
            if (pawn instanceof Creature) {
                if (this._fakePlayer.isOnGeodataPath()) {
                    this._fakePlayer.broadcastPacket(new MoveToLocation(this._fakePlayer));
                    this._clientMovingToPawnOffset = 0;
                } else if (sendPacket) {
                    this._fakePlayer.broadcastPacket(new MoveToPawn(this._fakePlayer, pawn, offset));
                }
            } else {
                this._fakePlayer.broadcastPacket(new MoveToLocation(this._fakePlayer));
            }
        }
    }

    public void moveTo(int x, int y, int z) {
        if (!this._fakePlayer.isMovementDisabled()) {
            this._clientMoving = true;
            this._clientMovingToPawnOffset = 0;
            this._fakePlayer.moveToLocation(x, y, z, 0);
            this._fakePlayer.broadcastPacket(new MoveToLocation(this._fakePlayer));
        }
    }

    protected boolean maybeMoveToPawn(WorldObject target, int offset) {
        if (target == null || offset < 0) {
            return false;
        }
        offset = (int)(offset + this._fakePlayer.getCollisionRadius());
        if (target instanceof Creature) {
            offset = (int)(offset + ((Creature)target).getCollisionRadius());
        }
        if (!this._fakePlayer.isInsideRadius(target, offset, false, false)) {
            if (this._fakePlayer.isMovementDisabled()) {
                if (_fakePlayer.getAI().getDesire().getIntention() == CtrlIntention.ATTACK) {
                    this._fakePlayer.getAI().setIntention(CtrlIntention.IDLE);
                }
                return true;
            }
            if (target instanceof Creature && !(target instanceof Door)) {
                if (((Creature)target).isMoving()) {
                    offset -= 30;
                }
                if (offset < 5) {
                    offset = 5;
                }
            }
            this.moveToPawn(target, offset);
            return true;
        }
        if (!GeoEngine.getInstance().canSeeTarget(this._fakePlayer, this._fakePlayer.getTarget())) {
            this._fakePlayer.setIsCastingNow(false);
            this.moveToPawn(target, 50);
            return true;
        }
        return false;
    }

    public abstract void thinkAndAct();

    protected abstract ArrayList<Integer> getBuffs();
}

 

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...