Fixup being able to kill monsters without correct slayer level (#220)

* Cannon only fire at npcs on same height level.

* Cannon cannot kill monsters if you do not have the slayer level
This commit is contained in:
Danial
2019-11-29 18:04:53 +13:00
committed by Daniel Ginovker
parent 680a0c2ee0
commit d4b16a25aa
@@ -404,56 +404,59 @@ public class DwarfCannon {
private Npc targetNpc() { private Npc targetNpc() {
for (int i = 0; i < NpcHandler.MAX_NPCS; i++) { for (int i = 0; i < NpcHandler.MAX_NPCS; i++) {
if (NpcHandler.npcs[i] == null) { Npc npc = NpcHandler.npcs[i];
continue; if (npc == null || npc.heightLevel != player.heightLevel || !canAttackSlayer(i)) {
} continue;
Npc npc = NpcHandler.npcs[i]; }
int myX = player.cannonX; int myX = player.cannonX;
int myY = player.cannonY; int myY = player.cannonY;
int theirX = npc.absX; int theirX = npc.absX;
int theirY = npc.absY; int theirY = npc.absY;
if (!npc.isDead && !npc.isDead && npc.HP != 0 && npc.npcType != 1266 && npc.npcType != 1268 && inDistance(theirX, theirY)) {
switch (rotation) {
case 1:
if (theirY > myY && theirX >= myX - 1 && theirX <= myX + 1) { if (!npc.isDead && !npc.isDead && npc.HP != 0 && npc.npcType != 1266 && npc.npcType != 1268 && inDistance(theirX, theirY)) {
return npc; switch (rotation) {
} case 1:
break; if (theirY > myY && theirX >= myX - 1 && theirX <= myX + 1) {
case 2: return npc;
if (theirX >= myX + 1 && theirY >= myY + 1) { }
return npc; break;
} case 2:
break; if (theirX >= myX + 1 && theirY >= myY + 1) {
case 3: return npc;
if (theirX > myX && theirY >= myY - 1 && theirY <= myY + 1) { }
return npc; break;
} case 3:
break; if (theirX > myX && theirY >= myY - 1 && theirY <= myY + 1) {
case 4: return npc;
if (theirY <= myY - 1 && theirX >= myX + 1) { }
return npc; break;
} case 4:
break; if (theirY <= myY - 1 && theirX >= myX + 1) {
case 5: return npc;
if (theirY < myY && theirX >= myX - 1 && theirX <= myX + 1) { }
return npc; break;
} case 5:
break; if (theirY < myY && theirX >= myX - 1 && theirX <= myX + 1) {
case 6: return npc;
if (theirX <= myX - 1 && theirY <= myY - 1) { }
return npc; break;
} case 6:
break; if (theirX <= myX - 1 && theirY <= myY - 1) {
case 7: return npc;
if (theirX < myX && theirY >= myY - 1 && theirY <= myY + 1) { }
return npc; break;
} case 7:
break; if (theirX < myX && theirY >= myY - 1 && theirY <= myY + 1) {
case 8: return npc;
if (theirX <= myX - 1 && theirY >= myY + 1) { }
return npc; break;
} case 8:
break; if (theirX <= myX - 1 && theirY >= myY + 1) {
return npc;
}
break;
} }
} }
} }
@@ -463,6 +466,10 @@ public class DwarfCannon {
public boolean inDistance(int npcX, int npcY) { public boolean inDistance(int npcX, int npcY) {
return (npcX >= player.cannonX - maxDistance && npcX <= player.cannonX + maxDistance && npcY >= player.cannonY - maxDistance && npcY <= player.cannonY + maxDistance); return (npcX >= player.cannonX - maxDistance && npcX <= player.cannonX + maxDistance && npcY >= player.cannonY - maxDistance && npcY <= player.cannonY + maxDistance);
} }
public boolean canAttackSlayer(int i){
return player.playerLevel[player.playerSlayer] >= player.getSlayer().getRequiredLevel(NpcHandler.npcs[i].npcType);
}
private void cannonProjectile(Npc n) { private void cannonProjectile(Npc n) {
int oX = player.cannonX+getShootXPos(); int oX = player.cannonX+getShootXPos();