Still having an issue with NPC's not considering distance between the target.
Skeletal Wyvern's for example are scripted to attack from a distance (unless you close the gap), but they're the ones closing the gap and ignoring the other combat styles. (I followed the Mithril Dragon combat script), and still no avail. Yet Mithril Dragons have no issue?
Am I doing something wrong in the Combat Script?
Code:
import com.rs.game.Animation;
import com.rs.game.Entity;
import com.rs.game.Graphics;
import com.rs.game.npc.NPC;
import com.rs.game.npc.combat.CombatScript;
import com.rs.game.npc.combat.NPCCombatDefinitions;
import com.rs.game.player.Player;
import com.rs.utils.Utils;
public class SkeletalWyvernCombat extends CombatScript {
@Override
public Object[] getKeys() {
return new Object[] { 3068, 3069, 3070, 3071, 3072 };
}
private static boolean hasShield(Entity target) {
if (!(target instanceof Player))
return true;
int shieldId = ((Player) target).getEquipment().getShieldId();
return shieldId == 2890 || shieldId == 9731 || shieldId == 20436
|| shieldId == 20438 || shieldId == 18691 || shieldId == 24558 || shieldId == 24566;
}
@Override
public int attack(NPC npc, Entity target) {
final NPCCombatDefinitions defs = npc.getCombatDefinitions();
boolean withinMeleeDist = npc.withinDistance(target, 1);
boolean withinRangedAttackDist = npc.withinDistance(target, 5);
final Player player = target instanceof Player ? (Player) target
: null;
if (withinMeleeDist) {
switch (Utils.getRandom(6)) {
case 0:
case 1:
case 2:
case 3:
npc.animate(new Animation(1593));
delayHit(npc, 0, target, getMeleeHit(
npc, getRandomMaxHit(npc, defs.getMaxHit(),
NPCCombatDefinitions.MELEE, target)));
break;
case 4:
case 5:
npc.animate(new Animation(1592));
npc.gfx(new Graphics(501));
target.gfx(new Graphics(502));
if (Utils.random(10) == 0)
target.setFreezeDelay(5000);
delayHit(npc, 1, target, getRegularHit(npc,
Utils.getRandom(hasShield(target) ? 150 : 600)));
if (player.getEquipment().getShieldId() == 24558) {
player.getAppearence().generateAppearenceData();
player.animate(new Animation(6695));
player.gfx(new Graphics(1164, 1, 15));
player.getPackets().sendGameMessage(
"Your ancient wyvern shield absorbs the wyverns icey breath.");
}
break;
}
return defs.getAttackDelay();
} else if (withinRangedAttackDist) {
switch (Utils.getRandom(4)) {
case 0:
case 1:
npc.animate(new Animation(1589));
npc.gfx(new Graphics(499));
delayHit(npc, 1, target, getRangeHit(
npc, getRandomMaxHit(npc, defs.getMaxHit(),
NPCCombatDefinitions.RANGE, target)));
break;
case 2:
case 3:
npc.animate(new Animation(1592));
npc.gfx(new Graphics(501));
target.gfx(new Graphics(502));
if (Utils.random(10) == 0)
target.setFreezeDelay(5000);
delayHit(npc, 1, target, getRegularHit(
npc, Utils.getRandom(hasShield(target) ? 150 : 600)));
if (player.getEquipment().getShieldId() == 24558) {
player.getAppearence().generateAppearenceData();
player.animate(new Animation(6695));
player.gfx(new Graphics(1164, 1, 15));
player.getPackets().sendGameMessage(
"Your ancient wyvern shield absorbs the wyverns icey breath.");
}
break;
}
}
return defs.getAttackDelay();
}
}
They also seem to dislike multi-combat zones. (Seems as though it is delaying there attack because I am "in" combat")