player.setLastRun(GameEngine.getTime());
player.resetCombat(CombatState.RUNNING);
player.isMining(false);
if (opponent instanceof Npc) {
Npc n = (Npc) opponent;
n.unblock();
opponent.resetCombat(CombatState.WAITING);
if (n.getDef().aggressive) {
player.setLastNpcChasingYou(n);
Instance.getDelayedEventHandler().add(
new MiniEvent(player, 2000) {
public void action() {
final Npc npc = owner
.getLastNpcChasingYou();
owner.setLastNpcChasingYou(null);
if (npc.isBusy()
|| npc.getChasing() != null)
return;
npc.resetPath();
npc.setChasing(owner);
Instance.getDelayedEventHandler()
.add(new WalkMobToMobEvent(
npc, owner, 0) {
public void arrived() {
if (affectedMob
.isBusy()
|| owner.isBusy()) {
npc.setChasing(null);
return;
}
if (affectedMob
.inCombat()
|| owner.inCombat()) {
npc.setChasing(null);
return;
}
Player player = (Player) affectedMob;
player.resetPath();
player.setBusy(true);
npc.resetPath();
player.resetAll();
player.setStatus(Action.FIGHTING_MOB);
player.getActionSender()
.sendSound(
"underattack");
player.getActionSender()
.sendMessage(
"You are under attack!");
npc.setLocation(
player.getLocation(),
true);
for (Player p : npc
.getViewArea()
.getPlayersInView())
p.removeWatchedNpc(npc);
player.setBusy(true);
player.setSprite(9);
player.setOpponent(npc);
player.setCombatTimer();
npc.setBusy(true);
npc.setSprite(8);
npc.setOpponent(player);
npc.setCombatTimer();
npc.setChasing(null);
FightEvent fighting = new FightEvent(
player,
npc, true);
fighting.setLastRun(0);
world.getDelayedEventHandler()
.add(fighting);
}
public void failed() {
npc.setChasing(null);
}
});
}
});
}