From d4b16a25aa84382a53ec98a95ef14e1a4a923d00 Mon Sep 17 00:00:00 2001 From: Danial Date: Fri, 29 Nov 2019 18:04:53 +1300 Subject: [PATCH] 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 --- .../content/combat/range/DwarfCannon.java | 107 ++++++++++-------- 1 file changed, 57 insertions(+), 50 deletions(-) diff --git a/2006Redone Server/src/com/rebotted/game/content/combat/range/DwarfCannon.java b/2006Redone Server/src/com/rebotted/game/content/combat/range/DwarfCannon.java index 4fd80b71..d655701d 100644 --- a/2006Redone Server/src/com/rebotted/game/content/combat/range/DwarfCannon.java +++ b/2006Redone Server/src/com/rebotted/game/content/combat/range/DwarfCannon.java @@ -404,56 +404,59 @@ public class DwarfCannon { private Npc targetNpc() { for (int i = 0; i < NpcHandler.MAX_NPCS; i++) { - if (NpcHandler.npcs[i] == null) { - continue; - } - Npc npc = NpcHandler.npcs[i]; - int myX = player.cannonX; - int myY = player.cannonY; - int theirX = npc.absX; - 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) { - return npc; - } - break; - case 2: - if (theirX >= myX + 1 && theirY >= myY + 1) { - return npc; - } - break; - case 3: - if (theirX > myX && theirY >= myY - 1 && theirY <= myY + 1) { - return npc; - } - break; - case 4: - if (theirY <= myY - 1 && theirX >= myX + 1) { - return npc; - } - break; - case 5: - if (theirY < myY && theirX >= myX - 1 && theirX <= myX + 1) { - return npc; - } - break; - case 6: - if (theirX <= myX - 1 && theirY <= myY - 1) { - return npc; - } - break; - case 7: - if (theirX < myX && theirY >= myY - 1 && theirY <= myY + 1) { - return npc; - } - break; - case 8: - if (theirX <= myX - 1 && theirY >= myY + 1) { - return npc; - } - break; + Npc npc = NpcHandler.npcs[i]; + if (npc == null || npc.heightLevel != player.heightLevel || !canAttackSlayer(i)) { + continue; + } + int myX = player.cannonX; + int myY = player.cannonY; + int theirX = npc.absX; + 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) { + return npc; + } + break; + case 2: + if (theirX >= myX + 1 && theirY >= myY + 1) { + return npc; + } + break; + case 3: + if (theirX > myX && theirY >= myY - 1 && theirY <= myY + 1) { + return npc; + } + break; + case 4: + if (theirY <= myY - 1 && theirX >= myX + 1) { + return npc; + } + break; + case 5: + if (theirY < myY && theirX >= myX - 1 && theirX <= myX + 1) { + return npc; + } + break; + case 6: + if (theirX <= myX - 1 && theirY <= myY - 1) { + return npc; + } + break; + case 7: + if (theirX < myX && theirY >= myY - 1 && theirY <= myY + 1) { + return npc; + } + break; + case 8: + if (theirX <= myX - 1 && theirY >= myY + 1) { + return npc; + } + break; } } } @@ -463,6 +466,10 @@ public class DwarfCannon { public boolean inDistance(int npcX, int npcY) { 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) { int oX = player.cannonX+getShootXPos();