well im working on dwarf multi cannon, i got everything down except the checking npc distance to see when cannon can shoot, these are the methods i have atm:
Code:
public static void checkNPCDistance() {
for (Player p : PlayerHandler.players) {
if (p == null)
return;
Client players = (Client) p;
NPC n = getNPCWithinDistance(players, players.cannonBaseX, players.cannonBaseY, players.cannonBaseH);
int damage = Misc.random(30);
if (players.inMulti() && n.inMulti()) {
startCannonballProjectile(players, players.oldCannon, n);
n.hitDiff = damage;
n.HP -= damage;
n.hitUpdateRequired = true;
n.killerId = players.playerId;
n.facePlayer(players.playerId);
n.forceChat("im hit, multi");
} else {
if (n.underAttackBy > 0 && n.underAttackBy != players.playerId)
return;
startCannonballProjectile(players, players.oldCannon, n);
n.hitDiff = damage;
n.HP -= damage;
n.hitUpdateRequired = true;
n.killerId = players.playerId;
n.facePlayer(players.playerId);
n.forceChat("im hit, single");
}
players.cannonBalls--;
}
}
private static NPC getNPCWithinDistance(Client players, int x, int y, int height) {
NPC npc = null;
for (int i = 0; i < NPCHandler.maxNPCs; i++) {
if (Server.npcHandler.npcs[i] == null)
return null;
npc = (NPC) Server.npcHandler.npcs[i];
}
int myX = players.cannonBaseX;
int myY = players.cannonBaseY;
int theirX = npc.absX;
int theirY = npc.absY;
if (!npc.isDead && npc.heightLevel == height && !npc.isDead && npc.HP != 0 && npc.npcType != 1266 && npc.npcType != 1268 && npc.petID < 1) {
switch (players.rotation) {
case 1: //north
if(theirY > myY && theirX >= myX - 1 && theirX <= myX + 1)
return npc;
break;
case 2: //north-east
if(theirX >= myX + 1 && theirY >= myY + 1)
return npc;
break;
case 3: //east
if(theirX > myX && theirY >= myY - 1 && theirY <= myY + 1)
return npc;
break;
case 4: //south-east
if(theirY <= myY - 1 && theirX >= myX + 1)
return npc;
break;
case 5: //south
if(theirY < myY && theirX >= myX - 1 && theirX <= myX + 1)
return npc;
break;
case 6: //south-west
if(theirX <= myX - 1 && theirY <= myY - 1)
return npc;
break;
case 7: //west
if(theirX < myX && theirY >= myY - 1 && theirY <= myY + 1)
return npc;
break;
case 8: //north-west
if(theirX <= myX - 1 && theirY >= myY + 1)
return npc;
break;
}
}
return null;
}
also when players lay down their cannon i have this
Code:
player.cannonBaseX = player.absX;
player.cannonBaseY = player.absY;
player.cannonBaseH = player.heightLevel;
just incase your wondering