Fix Some NPC's Turning When Clicked That Shouldn't (#624)

* Fix Some NPC's That Shouldn't Turn When Clicked

* Fix Some NPC's That Shouldn't Turn When Clicked

* Make immobileNpcs private

* Npc.java IntelliJ Code Format
This commit is contained in:
Josh Shippam
2023-02-23 04:18:57 +00:00
committed by GitHub
parent 566d04744c
commit 6fecac4b55
7 changed files with 457 additions and 442 deletions
@@ -64,7 +64,7 @@ public class CombatAssistant {
} }
player.getPacketSender().sendSound(CombatSounds.getNpcBlockSound(NpcHandler.npcs[player.oldNpcIndex].npcType), 100, 0); player.getPacketSender().sendSound(CombatSounds.getNpcBlockSound(NpcHandler.npcs[player.oldNpcIndex].npcType), 100, 0);
} }
NpcHandler.npcs[i].facePlayer(player.playerId); NpcHandler.npcs[i].facePlayer(player);
if (NpcHandler.npcs[i].underAttackBy > 0 && GameEngine.npcHandler.getsPulled(player, i)) { if (NpcHandler.npcs[i].underAttackBy > 0 && GameEngine.npcHandler.getsPulled(player, i)) {
NpcHandler.npcs[i].killerId = player.playerId; NpcHandler.npcs[i].killerId = player.playerId;
} else if (NpcHandler.npcs[i].underAttackBy < 0 && !GameEngine.npcHandler.getsPulled(player, i)) { } else if (NpcHandler.npcs[i].underAttackBy < 0 && !GameEngine.npcHandler.getsPulled(player, i)) {
@@ -157,11 +157,11 @@ public class NpcCombat {
if (!NpcData.goodDistanceNpc(NpcHandler.npcs[i].npcId, c.getX(), c.getY(), NpcData.distanceRequired(NpcHandler.npcs[i].npcId)) || NpcData.inNpc(NpcHandler.npcs[i].npcId, c.getX(), c.getY())) { if (!NpcData.goodDistanceNpc(NpcHandler.npcs[i].npcId, c.getX(), c.getY(), NpcData.distanceRequired(NpcHandler.npcs[i].npcId)) || NpcData.inNpc(NpcHandler.npcs[i].npcId, c.getX(), c.getY())) {
return; return;
} }
NpcHandler.npcs[i].facePlayer(c.playerId); NpcHandler.npcs[i].facePlayer(c);
boolean special = false;//specialCase(c,i); boolean special = false;//specialCase(c,i);
if (NpcData.checkClip(NpcHandler.npcs[i]) || special) { if (NpcData.checkClip(NpcHandler.npcs[i]) || special) {
if (c.respawnTimer <= 0) { if (c.respawnTimer <= 0) {
NpcHandler.npcs[i].facePlayer(c.playerId); NpcHandler.npcs[i].facePlayer(c);
NpcHandler.npcs[i].attackTimer = NpcData.getNpcDelay(i); NpcHandler.npcs[i].attackTimer = NpcData.getNpcDelay(i);
NpcHandler.npcs[i].hitDelayTimer = NpcData.getHitDelay(i); NpcHandler.npcs[i].hitDelayTimer = NpcData.getHitDelay(i);
NpcHandler.npcs[i].attackType = 0; NpcHandler.npcs[i].attackType = 0;
@@ -428,7 +428,7 @@ public class DwarfCannon {
player.globalDamageDealt += damage; player.globalDamageDealt += damage;
target.killerId = player.playerId; target.killerId = player.playerId;
target.killedBy = player.playerId; target.killedBy = player.playerId;
target.facePlayer(player.playerId); target.facePlayer(player);
target.hitUpdateRequired2 = true; target.hitUpdateRequired2 = true;
target.updateRequired = true; target.updateRequired = true;
myBalls -= 1; myBalls -= 1;
@@ -251,7 +251,7 @@ public class Pickpocket extends SkillHandler {
if (player.goodDistance(player.absX, player.absY, NpcHandler.npcs[i].absX, NpcHandler.npcs[i].absY, 1) && player.heightLevel == NpcHandler.npcs[i].heightLevel) { if (player.goodDistance(player.absX, player.absY, NpcHandler.npcs[i].absX, NpcHandler.npcs[i].absY, 1) && player.heightLevel == NpcHandler.npcs[i].heightLevel) {
if (!NpcHandler.npcs[i].underAttack) { if (!NpcHandler.npcs[i].underAttack) {
NpcHandler.npcs[i].forceChat("What do you think you're doing?"); NpcHandler.npcs[i].forceChat("What do you think you're doing?");
NpcHandler.npcs[i].facePlayer(player.playerId); NpcHandler.npcs[i].facePlayer(player);
} }
} }
} }
@@ -9,463 +9,479 @@ import com.rs2.game.players.PlayerHandler;
import com.rs2.util.Misc; import com.rs2.util.Misc;
import com.rs2.util.Stream; import com.rs2.util.Stream;
import static com.rs2.game.content.StaticNpcList.*;
public class Npc { public class Npc {
public int npcId; public int npcId;
public int npcType; public int npcType;
public int absX, absY; public int absX, absY;
public int heightLevel; public int heightLevel;
public static int lastX, lastY; public static int lastX, lastY;
public int makeX, makeY, maxHit, defence, attack, moveX, moveY, direction, walkingType, hitsToHeal; public int makeX, makeY, maxHit, defence, attack, moveX, moveY, direction, walkingType, hitsToHeal;
public int spawnX, spawnY; public int spawnX, spawnY;
public int viewX, viewY; public int viewX, viewY;
public boolean summoner; public boolean summoner;
public int summonedBy, size; public int summonedBy, size;
public int focusPointX, focusPointY, masterId; public int focusPointX, focusPointY, masterId;
public boolean turnUpdateRequired; public boolean turnUpdateRequired;
public int chasingRat = -1; public int chasingRat = -1;
/** /**
* attackType: 0 = melee, 1 = range, 2 = mage * attackType: 0 = melee, 1 = range, 2 = mage
*/ */
public int attackType, projectileId, endGfx, spawnedBy, hitDelayTimer, HP, public int attackType, projectileId, endGfx, spawnedBy, hitDelayTimer, HP,
MaxHP, hitDiff, animNumber, actionTimer, enemyX, enemyY, MaxHP, hitDiff, animNumber, actionTimer, enemyX, enemyY,
combatLevel; combatLevel;
public boolean applyDead, isDead, needRespawn, respawns, aggressive; public boolean applyDead, isDead, needRespawn, respawns, aggressive;
public boolean walkingHome, underAttack; public boolean walkingHome, underAttack;
public int freezeTimer, attackTimer, killerId, killedBy, oldIndex, public int freezeTimer, attackTimer, killerId, killedBy, oldIndex,
underAttackBy; underAttackBy;
public long lastDamageTaken; public long lastDamageTaken;
public boolean randomWalk; public boolean randomWalk;
public boolean dirUpdateRequired; public boolean dirUpdateRequired;
public boolean animUpdateRequired; public boolean animUpdateRequired;
public boolean hitUpdateRequired; public boolean hitUpdateRequired;
public boolean updateRequired; public boolean updateRequired;
public boolean forcedChatRequired; public boolean forcedChatRequired;
public boolean faceToUpdateRequired; public boolean faceToUpdateRequired;
public int firstAttacker; public int firstAttacker;
public String forcedText; public String forcedText;
public boolean transformUpdateRequired = false, isTransformed = false; public boolean transformUpdateRequired = false, isTransformed = false;
public int transformId; public int transformId;
public Npc(int _npcId, int _npcType) {
npcId = _npcId;
npcType = _npcType;
direction = -1;
isDead = false;
applyDead = false;
actionTimer = 0;
randomWalk = true;
}
public void requestTransform(int id) {
transformId = id;
transformUpdateRequired = true;
updateRequired = true;
}
public void shearSheep(Player player, int itemNeeded, int itemGiven, int animation, final int currentId, final int newId, int transformTime) {
if (!player.getItemAssistant().playerHasItem(itemNeeded)) {
player.getPacketSender().sendMessage("You need " + DeprecatedItems.getItemName(itemNeeded).toLowerCase() + " to do that.");
return;
}
if (transformId == newId) {
player.getPacketSender().sendMessage("This sheep has already been shorn.");
return;
}
if (NpcHandler.npcs[npcId].isTransformed) {
return;
}
if (animation > 0) {
player.startAnimation(animation);
}
requestTransform(newId);
player.getItemAssistant().addItem(itemGiven, 1);
player.getPacketSender().sendMessage("You get some " + DeprecatedItems.getItemName(itemGiven).toLowerCase() + ".");
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override public Npc(int _npcId, int _npcType) {
public void execute(CycleEventContainer container) { npcId = _npcId;
requestTransform(currentId); npcType = _npcType;
container.stop(); direction = -1;
} isDead = false;
applyDead = false;
actionTimer = 0;
randomWalk = true;
}
@Override public void requestTransform(int id) {
public void stop() { transformId = id;
NpcHandler.npcs[npcId].isTransformed = false; transformUpdateRequired = true;
} updateRequired = true;
}, transformTime); }
}
public void appendTransformUpdate(Stream str) {
str.writeWordBigEndianA(transformId);
}
public void updateNPCMovement(Stream str) { public void shearSheep(Player player, int itemNeeded, int itemGiven, int animation, final int currentId, final int newId, int transformTime) {
if (!player.getItemAssistant().playerHasItem(itemNeeded)) {
player.getPacketSender().sendMessage("You need " + DeprecatedItems.getItemName(itemNeeded).toLowerCase() + " to do that.");
return;
}
if (transformId == newId) {
player.getPacketSender().sendMessage("This sheep has already been shorn.");
return;
}
if (NpcHandler.npcs[npcId].isTransformed) {
return;
}
if (animation > 0) {
player.startAnimation(animation);
}
requestTransform(newId);
player.getItemAssistant().addItem(itemGiven, 1);
player.getPacketSender().sendMessage("You get some " + DeprecatedItems.getItemName(itemGiven).toLowerCase() + ".");
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
if (str != null) { @Override
if (direction == -1) { public void execute(CycleEventContainer container) {
requestTransform(currentId);
container.stop();
}
if (updateRequired) { @Override
public void stop() {
NpcHandler.npcs[npcId].isTransformed = false;
}
}, transformTime);
}
str.writeBits(1, 1); public void appendTransformUpdate(Stream str) {
str.writeBits(2, 0); str.writeWordBigEndianA(transformId);
} else { }
str.writeBits(1, 0);
}
} else {
str.writeBits(1, 1);
str.writeBits(2, 1);
str.writeBits(3, Misc.xlateDirectionToClient[direction]);
if (updateRequired) {
str.writeBits(1, 1);
} else {
str.writeBits(1, 0);
}
}
}
}
/**
* Text update
**/
public void forceChat(String text) {
forcedText = text;
forcedChatRequired = true;
updateRequired = true;
}
/** public void updateNPCMovement(Stream str) {
* Graphics
**/
public int mask80var1 = 0; if (str != null) {
public int mask80var2 = 0; if (direction == -1) {
protected boolean mask80update = false;
public void appendMask80Update(Stream str) { if (updateRequired) {
str.writeWord(mask80var1);
str.writeDWord(mask80var2);
}
public void gfx100(int gfx) { str.writeBits(1, 1);
mask80var1 = gfx; str.writeBits(2, 0);
mask80var2 = 6553600; } else {
mask80update = true; str.writeBits(1, 0);
updateRequired = true; }
} } else {
public void gfx0(int gfx) { str.writeBits(1, 1);
mask80var1 = gfx; str.writeBits(2, 1);
mask80var2 = 65536; str.writeBits(3, Misc.xlateDirectionToClient[direction]);
mask80update = true; if (updateRequired) {
updateRequired = true; str.writeBits(1, 1);
} } else {
str.writeBits(1, 0);
}
}
}
}
public void appendAnimUpdate(Stream str) { /**
str.writeWordBigEndian(animNumber); * Text update
str.writeByte(1); **/
}
public int startAnimation(int anim, int npcId) {
return animNumber;
}
/** public void forceChat(String text) {
* forcedText = text;
Face forcedChatRequired = true;
**/ updateRequired = true;
}
public int FocusPointX = -1, FocusPointY = -1;
public int face = 0;
private void appendSetFocusDestination(Stream str) { /**
str.writeWordBigEndian(FocusPointX); * Graphics
str.writeWordBigEndian(FocusPointY); **/
}
public void turnNpc(int i, int j) { public int mask80var1 = 0;
FocusPointX = 2 * i + 1; public int mask80var2 = 0;
FocusPointY = 2 * j + 1; protected boolean mask80update = false;
updateRequired = true;
turnUpdateRequired = true;
}
public int getNextWalkingDirection2() { public void appendMask80Update(Stream str) {
int dir; str.writeWord(mask80var1);
dir = Misc.direction(absX, absY, absX + moveX, absY + moveY); str.writeDWord(mask80var2);
dir >>= 1; }
absX += moveX;
absY += moveY;
return dir;
}
public void getRandomAndHomeNPCWalking(int i) { public void gfx100(int gfx) {
direction = -1; mask80var1 = gfx;
if (NpcHandler.npcs[i].freezeTimer == 0) { mask80var2 = 6553600;
direction = getNextWalkingDirection2(); mask80update = true;
} updateRequired = true;
} }
public void appendFaceEntity(Stream str) { public void gfx0(int gfx) {
str.writeWord(face); mask80var1 = gfx;
} mask80var2 = 65536;
mask80update = true;
updateRequired = true;
}
public void facePlayer(int player) { public void appendAnimUpdate(Stream str) {
face = player + 32768; str.writeWordBigEndian(animNumber);
dirUpdateRequired = true; str.writeByte(1);
updateRequired = true; }
}
public void appendFaceToUpdate(Stream str) { public int startAnimation(int anim, int npcId) {
str.writeWordBigEndian(viewX); return animNumber;
str.writeWordBigEndian(viewY); }
}
public void appendNPCUpdateBlock(Stream str) { /**
if (!updateRequired) { * Face
return; **/
}
int updateMask = 0;
if (animUpdateRequired) {
updateMask |= 0x10;
}
if (hitUpdateRequired2) {
updateMask |= 8;
}
if (mask80update) {
updateMask |= 0x80;
}
if (dirUpdateRequired) {
updateMask |= 0x20;
}
if (forcedChatRequired) {
updateMask |= 1;
}
if (hitUpdateRequired) {
updateMask |= 0x40;
}
if (transformUpdateRequired) {
updateMask |= 2;
}
if (turnUpdateRequired) {
updateMask |= 4;
}
str.writeByte(updateMask); public int FocusPointX = -1, FocusPointY = -1;
public int face = 0;
if (animUpdateRequired) { private void appendSetFocusDestination(Stream str) {
appendAnimUpdate(str); str.writeWordBigEndian(FocusPointX);
} str.writeWordBigEndian(FocusPointY);
if (hitUpdateRequired2) { }
appendHitUpdate2(str);
}
if (mask80update) {
appendMask80Update(str);
}
if (dirUpdateRequired) {
appendFaceEntity(str);
}
if (forcedChatRequired) {
str.writeString(forcedText);
}
if (hitUpdateRequired) {
appendHitUpdate(str);
}
if (transformUpdateRequired) {
appendTransformUpdate(str);
}
if (turnUpdateRequired) {
appendSetFocusDestination(str);
}
} public void turnNpc(int i, int j) {
FocusPointX = 2 * i + 1;
FocusPointY = 2 * j + 1;
updateRequired = true;
turnUpdateRequired = true;
}
public void clearUpdateFlags() { public int getNextWalkingDirection2() {
updateRequired = false; int dir;
forcedChatRequired = false; dir = Misc.direction(absX, absY, absX + moveX, absY + moveY);
hitUpdateRequired = false; dir >>= 1;
hitUpdateRequired2 = false; absX += moveX;
animUpdateRequired = false; absY += moveY;
dirUpdateRequired = false; return dir;
transformUpdateRequired = false; }
mask80update = false;
forcedText = null;
moveX = 0;
moveY = 0;
direction = -1;
focusPointX = -1;
focusPointY = -1;
turnUpdateRequired = false;
}
public int getNextWalkingDirection() { public void getRandomAndHomeNPCWalking(int i) {
int nextX = absX + moveX; direction = -1;
int nextY = absY + moveY; if (NpcHandler.npcs[i].freezeTimer == 0) {
int dir; direction = getNextWalkingDirection2();
dir = Misc.direction(absX, absY, absX + moveX, absY + moveY); }
for (Npc npc : NpcHandler.npcs) { }
if (npc == null) {
continue;
}
if (npc.absX == nextX && npc.absY == nextY
&& npc.heightLevel == heightLevel) {
return -1;
}
}
for (Player p : PlayerHandler.players) {
if (p == null) {
continue;
}
if (p.absX == nextX && p.absY == nextY
&& p.heightLevel == heightLevel) {
return -1;
}
}
if (dir == -1) {
return -1;
}
dir >>= 1;
absX += moveX;
absY += moveY;
return dir;
}
public void getNextNPCMovement(int i) { public void appendFaceEntity(Stream str) {
direction = -1; str.writeWord(face);
if (NpcHandler.npcs[i].freezeTimer == 0) { }
direction = getNextWalkingDirection();
}
}
public void appendHitUpdate(Stream str) { /**
if (HP <= 0) { * NPC's That Don't Turn To Face The Player When Clicked
isDead = true; */
} private static int[] immobileNpcs = { //TODO Rename Appropriately
str.writeByteC(hitDiff); OSPAK,
if (hitDiff > 0) { STYRMIR,
str.writeByteS(1); TORBRUND,
} else { FRIDGEIR,
str.writeByteS(0); };
}
str.writeByteS(HP);
str.writeByteC(MaxHP);
}
public int hitDiff2 = 0; public void facePlayer(Player player) {
public boolean hitUpdateRequired2 = false; for (int element : immobileNpcs) {
if (npcType == (element)) {
return;
}
}
face = (player != null) ? player.playerId + 32768 : 32768;
dirUpdateRequired = true;
updateRequired = true;
}
public void appendHitUpdate2(Stream str) { public void appendFaceToUpdate(Stream str) {
if (HP <= 0) { str.writeWordBigEndian(viewX);
isDead = true; str.writeWordBigEndian(viewY);
} }
str.writeByteA(hitDiff2);
if (hitDiff2 > 0) {
str.writeByteC(1);
} else {
str.writeByteC(0);
}
str.writeByteA(HP);
str.writeByte(MaxHP);
}
public void handleHitMask(int damage) { public void appendNPCUpdateBlock(Stream str) {
if (!hitUpdateRequired) { if (!updateRequired) {
hitUpdateRequired = true; return;
hitDiff = damage; }
} else if (!hitUpdateRequired2) { int updateMask = 0;
hitUpdateRequired2 = true; if (animUpdateRequired) {
hitDiff2 = damage; updateMask |= 0x10;
} }
updateRequired = true; if (hitUpdateRequired2) {
} updateMask |= 8;
}
if (mask80update) {
updateMask |= 0x80;
}
if (dirUpdateRequired) {
updateMask |= 0x20;
}
if (forcedChatRequired) {
updateMask |= 1;
}
if (hitUpdateRequired) {
updateMask |= 0x40;
}
if (transformUpdateRequired) {
updateMask |= 2;
}
if (turnUpdateRequired) {
updateMask |= 4;
}
public int getX() { str.writeByte(updateMask);
return absX;
}
public int getY() { if (animUpdateRequired) {
return absY; appendAnimUpdate(str);
} }
if (hitUpdateRequired2) {
appendHitUpdate2(str);
}
if (mask80update) {
appendMask80Update(str);
}
if (dirUpdateRequired) {
appendFaceEntity(str);
}
if (forcedChatRequired) {
str.writeString(forcedText);
}
if (hitUpdateRequired) {
appendHitUpdate(str);
}
if (transformUpdateRequired) {
appendTransformUpdate(str);
}
if (turnUpdateRequired) {
appendSetFocusDestination(str);
}
public int getLastX() { }
return lastX;
}
public int getLastY() { public void clearUpdateFlags() {
return lastY; updateRequired = false;
} forcedChatRequired = false;
hitUpdateRequired = false;
hitUpdateRequired2 = false;
animUpdateRequired = false;
dirUpdateRequired = false;
transformUpdateRequired = false;
mask80update = false;
forcedText = null;
moveX = 0;
moveY = 0;
direction = -1;
focusPointX = -1;
focusPointY = -1;
turnUpdateRequired = false;
}
public void setAbsX(int absX) { public int getNextWalkingDirection() {
Npc.lastX = this.absX; int nextX = absX + moveX;
this.absX = absX; int nextY = absY + moveY;
} int dir;
dir = Misc.direction(absX, absY, absX + moveX, absY + moveY);
for (Npc npc : NpcHandler.npcs) {
if (npc == null) {
continue;
}
if (npc.absX == nextX && npc.absY == nextY
&& npc.heightLevel == heightLevel) {
return -1;
}
}
for (Player p : PlayerHandler.players) {
if (p == null) {
continue;
}
if (p.absX == nextX && p.absY == nextY
&& p.heightLevel == heightLevel) {
return -1;
}
}
if (dir == -1) {
return -1;
}
dir >>= 1;
absX += moveX;
absY += moveY;
return dir;
}
public void setAbsY(int absY) { public void getNextNPCMovement(int i) {
Npc.lastY = this.absY; direction = -1;
this.absY = absY; if (NpcHandler.npcs[i].freezeTimer == 0) {
} direction = getNextWalkingDirection();
}
}
public void deleteNPC(Npc npc) { public void appendHitUpdate(Stream str) {
setAbsX(0); if (HP <= 0) {
setAbsY(0); isDead = true;
npc = null; }
} str.writeByteC(hitDiff);
if (hitDiff > 0) {
public boolean inLesserNpc() { str.writeByteS(1);
return (absX >= 3108 && absX <= 3112 && absY >= 3156 && absY <= 3158 && heightLevel == 2); } else {
} str.writeByteS(0);
}
str.writeByteS(HP);
str.writeByteC(MaxHP);
}
public boolean inMulti() { public int hitDiff2 = 0;
if (absX >= 3136 public boolean hitUpdateRequired2 = false;
&& absX <= 3327
&& absY >= 3519
&& absY <= 3607
|| absX >= 2625
&& absX <= 2685
&& absY >= 2550
&& absY <= 2620 // Pest
// Control
|| absX >= 3190 && absX <= 3327 && absY >= 3648 && absY <= 3839
|| absX >= 3200 && absX <= 3390 && absY >= 3840 && absY <= 3967
|| absX >= 2992
&& absX <= 3007
&& absY >= 3912
&& absY <= 3967
|| absX >= 2946
&& absX <= 2959
&& absY >= 3816
&& absY <= 3831
|| absX >= 3008
&& absX <= 3199
&& absY >= 3856
&& absY <= 3903
|| absX >= 2667
&& absX <= 2685
&& absY >= 3712
&& absY <= 3730 // rock
// crabs
|| absX >= 3008 && absX <= 3071 && absY >= 3600 && absY <= 3711
|| absX >= 3072 && absX <= 3327 && absY >= 3608 && absY <= 3647
|| absX >= 2624 && absX <= 2690 && absY >= 2550 && absY <= 2619
|| absX >= 2371 && absX <= 2422 && absY >= 5062 && absY <= 5117
|| absX >= 2896 && absX <= 2927 && absY >= 3595 && absY <= 3630
|| absX >= 2892 && absX <= 2932 && absY >= 4435 && absY <= 4464
|| absX >= 2256 && absX <= 2287 && absY >= 4680 && absY <= 4711) {
return true;
}
return false;
}
public boolean inWild() {// beg, end, beg, end, beg, end, beg, end public void appendHitUpdate2(Stream str) {
if (absX > 2941 && absX < 3392 && absY > 3518 && absY < 3966 if (HP <= 0) {
|| absX > 2941 && absX < 3392 && absY > 9918 && absY < 10366) { isDead = true;
return true; }
} str.writeByteA(hitDiff2);
return false; if (hitDiff2 > 0) {
} str.writeByteC(1);
} else {
str.writeByteC(0);
}
str.writeByteA(HP);
str.writeByte(MaxHP);
}
public void handleHitMask(int damage) {
if (!hitUpdateRequired) {
hitUpdateRequired = true;
hitDiff = damage;
} else if (!hitUpdateRequired2) {
hitUpdateRequired2 = true;
hitDiff2 = damage;
}
updateRequired = true;
}
public int getX() {
return absX;
}
public int getY() {
return absY;
}
public int getLastX() {
return lastX;
}
public int getLastY() {
return lastY;
}
public void setAbsX(int absX) {
Npc.lastX = this.absX;
this.absX = absX;
}
public void setAbsY(int absY) {
Npc.lastY = this.absY;
this.absY = absY;
}
public void deleteNPC(Npc npc) {
setAbsX(0);
setAbsY(0);
npc = null;
}
public boolean inLesserNpc() {
return (absX >= 3108 && absX <= 3112 && absY >= 3156 && absY <= 3158 && heightLevel == 2);
}
public boolean inMulti() {
if (absX >= 3136
&& absX <= 3327
&& absY >= 3519
&& absY <= 3607
|| absX >= 2625
&& absX <= 2685
&& absY >= 2550
&& absY <= 2620 // Pest
// Control
|| absX >= 3190 && absX <= 3327 && absY >= 3648 && absY <= 3839
|| absX >= 3200 && absX <= 3390 && absY >= 3840 && absY <= 3967
|| absX >= 2992
&& absX <= 3007
&& absY >= 3912
&& absY <= 3967
|| absX >= 2946
&& absX <= 2959
&& absY >= 3816
&& absY <= 3831
|| absX >= 3008
&& absX <= 3199
&& absY >= 3856
&& absY <= 3903
|| absX >= 2667
&& absX <= 2685
&& absY >= 3712
&& absY <= 3730 // rock
// crabs
|| absX >= 3008 && absX <= 3071 && absY >= 3600 && absY <= 3711
|| absX >= 3072 && absX <= 3327 && absY >= 3608 && absY <= 3647
|| absX >= 2624 && absX <= 2690 && absY >= 2550 && absY <= 2619
|| absX >= 2371 && absX <= 2422 && absY >= 5062 && absY <= 5117
|| absX >= 2896 && absX <= 2927 && absY >= 3595 && absY <= 3630
|| absX >= 2892 && absX <= 2932 && absY >= 4435 && absY <= 4464
|| absX >= 2256 && absX <= 2287 && absY >= 4680 && absY <= 4711) {
return true;
}
return false;
}
public boolean inWild() {// beg, end, beg, end, beg, end, beg, end
if (absX > 2941 && absX < 3392 && absY > 3518 && absY < 3966
|| absX > 2941 && absX < 3392 && absY > 9918 && absY < 10366) {
return true;
}
return false;
}
} }
@@ -193,7 +193,7 @@ public class NpcHandler {
newNPC.attack = attack; newNPC.attack = attack;
newNPC.defence = defence; newNPC.defence = defence;
newNPC.spawnedBy = c.getId(); newNPC.spawnedBy = c.getId();
newNPC.facePlayer(c.playerId); newNPC.facePlayer(c);
if (headIcon) { if (headIcon) {
c.getPacketSender().drawHeadicon(1, slot, 0, 0); c.getPacketSender().drawHeadicon(1, slot, 0, 0);
} }
@@ -461,7 +461,7 @@ public class NpcHandler {
if (slaveOwner != null && slaveOwner.hasNpc && npcs[i].summoner) { if (slaveOwner != null && slaveOwner.hasNpc && npcs[i].summoner) {
if (slaveOwner.goodDistance(npcs[i].absX, npcs[i].absY, slaveOwner.absX, slaveOwner.absY, 15)) { if (slaveOwner.goodDistance(npcs[i].absX, npcs[i].absY, slaveOwner.absX, slaveOwner.absY, 15)) {
NpcHandler.followPlayer(i, slaveOwner.playerId); NpcHandler.followPlayer(i, slaveOwner);
} }
} }
@@ -587,7 +587,7 @@ public class NpcHandler {
int p = npcs[i].killerId; int p = npcs[i].killerId;
if (PlayerHandler.players[p] != null) { if (PlayerHandler.players[p] != null) {
Player c = (Client) PlayerHandler.players[p]; Player c = (Client) PlayerHandler.players[p];
followPlayer(i, c.playerId); followPlayer(i, c);
if (npcs[i] == null) { if (npcs[i] == null) {
continue; continue;
} }
@@ -598,7 +598,7 @@ public class NpcHandler {
} else { } else {
npcs[i].killerId = 0; npcs[i].killerId = 0;
npcs[i].underAttack = false; npcs[i].underAttack = false;
npcs[i].facePlayer(0); npcs[i].facePlayer(null);
} }
} }
} }
@@ -611,7 +611,7 @@ public class NpcHandler {
} }
if ((!npcs[i].underAttack || npcs[i].walkingHome) if ((!npcs[i].underAttack || npcs[i].walkingHome)
&& npcs[i].randomWalk && !npcs[i].isDead) { && npcs[i].randomWalk && !npcs[i].isDead) {
npcs[i].facePlayer(0); npcs[i].facePlayer(null);
npcs[i].killerId = 0; npcs[i].killerId = 0;
if (npcs[i].spawnedBy == 0) { if (npcs[i].spawnedBy == 0) {
if (npcs[i].absX > npcs[i].makeX if (npcs[i].absX > npcs[i].makeX
@@ -730,7 +730,7 @@ public class NpcHandler {
if (npcs[i].isDead) { if (npcs[i].isDead) {
if (npcs[i].actionTimer == 0 && npcs[i].applyDead == false && npcs[i].needRespawn == false) { if (npcs[i].actionTimer == 0 && npcs[i].applyDead == false && npcs[i].needRespawn == false) {
npcs[i].updateRequired = true; npcs[i].updateRequired = true;
npcs[i].facePlayer(0); npcs[i].facePlayer(null);
npcs[i].killedBy = NpcData.getNpcKillerId(i); npcs[i].killedBy = NpcData.getNpcKillerId(i);
Player c = (Client) PlayerHandler.players[npcs[i].killedBy]; Player c = (Client) PlayerHandler.players[npcs[i].killedBy];
if (c != null) { if (c != null) {
@@ -1197,15 +1197,15 @@ public class NpcHandler {
return true; return true;
} }
public static void followPlayer(int i, int playerId) { public static void followPlayer(int i, Player player) {
if (PlayerHandler.players[playerId] == null) { if (player == null) {
return; return;
} }
if (PlayerHandler.players[playerId].npcCanAttack == false) { if (player.npcCanAttack == false) {
return; return;
} }
if (PlayerHandler.players[playerId].respawnTimer > 0) { if (player.respawnTimer > 0) {
npcs[i].facePlayer(0); npcs[i].facePlayer(null);
npcs[i].randomWalk = true; npcs[i].randomWalk = true;
npcs[i].underAttack = false; npcs[i].underAttack = false;
return; return;
@@ -1216,12 +1216,12 @@ public class NpcHandler {
} }
if (!followPlayer(i) && npcs[i].npcType != 1532 && npcs[i].npcType != 1534) { if (!followPlayer(i) && npcs[i].npcType != 1532 && npcs[i].npcType != 1534) {
npcs[i].facePlayer(playerId); npcs[i].facePlayer(player);
return; return;
} }
int playerX = PlayerHandler.players[playerId].absX; int playerX = player.absX;
int playerY = PlayerHandler.players[playerId].absY; int playerY = player.absY;
npcs[i].randomWalk = false; npcs[i].randomWalk = false;
if (goodDistance(npcs[i].getX(), npcs[i].getY(), playerX, playerY, distanceRequired(i))) { if (goodDistance(npcs[i].getX(), npcs[i].getY(), playerX, playerY, distanceRequired(i))) {
return; return;
@@ -1230,7 +1230,6 @@ public class NpcHandler {
Npc npc = npcs[i]; Npc npc = npcs[i];
int x = npc.absX; int x = npc.absX;
int y = npc.absY; int y = npc.absY;
Player player = PlayerHandler.players[playerId];
if (npcs[i].spawnedBy > 0 if (npcs[i].spawnedBy > 0
|| x < npc.makeX + Constants.NPC_FOLLOW_DISTANCE || x < npc.makeX + Constants.NPC_FOLLOW_DISTANCE
&& x > npc.makeX - Constants.NPC_FOLLOW_DISTANCE && x > npc.makeX - Constants.NPC_FOLLOW_DISTANCE
@@ -1259,14 +1258,14 @@ public class NpcHandler {
npc.moveX = GetMove(x, playerX); //Move East to player npc.moveX = GetMove(x, playerX); //Move East to player
npc.moveY = GetMove(y, playerY); npc.moveY = GetMove(y, playerY);
} }
npc.facePlayer(playerId); npc.facePlayer(player);
handleClipping(i); handleClipping(i);
npc.getRandomAndHomeNPCWalking(i); npc.getRandomAndHomeNPCWalking(i);
npc.updateRequired = true; npc.updateRequired = true;
} }
} }
} else { } else {
npc.facePlayer(0); npc.facePlayer(null);
npc.randomWalk = true; npc.randomWalk = true;
npc.underAttack = false; npc.underAttack = false;
} }
@@ -239,7 +239,7 @@ public class ClickNPC implements PacketType {
player.getY(), 2)) { player.getY(), 2)) {
player.turnPlayerTo(NpcHandler.npcs[player.npcClickIndex].getX(), player.turnPlayerTo(NpcHandler.npcs[player.npcClickIndex].getX(),
NpcHandler.npcs[player.npcClickIndex].getY()); NpcHandler.npcs[player.npcClickIndex].getY());
NpcHandler.npcs[player.npcClickIndex].facePlayer(player.playerId); NpcHandler.npcs[player.npcClickIndex].facePlayer(player);
player.getNpcs().firstClickNpc(player.npcType); player.getNpcs().firstClickNpc(player.npcType);
player.post(new NpcFirstClickEvent(player.npcType)); player.post(new NpcFirstClickEvent(player.npcType));
} else { } else {
@@ -256,7 +256,7 @@ public class ClickNPC implements PacketType {
NpcHandler.npcs[player.npcClickIndex].getX(), NpcHandler.npcs[player.npcClickIndex].getX(),
NpcHandler.npcs[player.npcClickIndex].getY()); NpcHandler.npcs[player.npcClickIndex].getY());
NpcHandler.npcs[player.npcClickIndex] NpcHandler.npcs[player.npcClickIndex]
.facePlayer(player.playerId); .facePlayer(player);
player.getNpcs().firstClickNpc(player.npcType); player.getNpcs().firstClickNpc(player.npcType);
player.post(new NpcFirstClickEvent(player.npcType)); player.post(new NpcFirstClickEvent(player.npcType));
container.stop(); container.stop();
@@ -282,7 +282,7 @@ public class ClickNPC implements PacketType {
player.getY(), 2)) { player.getY(), 2)) {
player.turnPlayerTo(NpcHandler.npcs[player.npcClickIndex].getX(), player.turnPlayerTo(NpcHandler.npcs[player.npcClickIndex].getX(),
NpcHandler.npcs[player.npcClickIndex].getY()); NpcHandler.npcs[player.npcClickIndex].getY());
NpcHandler.npcs[player.npcClickIndex].facePlayer(player.playerId); NpcHandler.npcs[player.npcClickIndex].facePlayer(player);
player.getNpcs().secondClickNpc(player.npcType); player.getNpcs().secondClickNpc(player.npcType);
player.post(new NpcSecondClickEvent(player.npcType)); player.post(new NpcSecondClickEvent(player.npcType));
} else { } else {
@@ -299,7 +299,7 @@ public class ClickNPC implements PacketType {
NpcHandler.npcs[player.npcClickIndex].getX(), NpcHandler.npcs[player.npcClickIndex].getX(),
NpcHandler.npcs[player.npcClickIndex].getY()); NpcHandler.npcs[player.npcClickIndex].getY());
NpcHandler.npcs[player.npcClickIndex] NpcHandler.npcs[player.npcClickIndex]
.facePlayer(player.playerId); .facePlayer(player);
player.getNpcs().secondClickNpc(player.npcType); player.getNpcs().secondClickNpc(player.npcType);
player.post(new NpcSecondClickEvent(player.npcType)); player.post(new NpcSecondClickEvent(player.npcType));
container.stop(); container.stop();
@@ -326,7 +326,7 @@ public class ClickNPC implements PacketType {
player.getY(), 2)) { player.getY(), 2)) {
player.turnPlayerTo(NpcHandler.npcs[player.npcClickIndex].getX(), player.turnPlayerTo(NpcHandler.npcs[player.npcClickIndex].getX(),
NpcHandler.npcs[player.npcClickIndex].getY()); NpcHandler.npcs[player.npcClickIndex].getY());
NpcHandler.npcs[player.npcClickIndex].facePlayer(player.playerId); NpcHandler.npcs[player.npcClickIndex].facePlayer(player);
player.getNpcs().thirdClickNpc(player.npcType); player.getNpcs().thirdClickNpc(player.npcType);
player.post(new NpcThirdClickEvent(player.npcType)); player.post(new NpcThirdClickEvent(player.npcType));
} else { } else {
@@ -343,7 +343,7 @@ public class ClickNPC implements PacketType {
NpcHandler.npcs[player.npcClickIndex].getX(), NpcHandler.npcs[player.npcClickIndex].getX(),
NpcHandler.npcs[player.npcClickIndex].getY()); NpcHandler.npcs[player.npcClickIndex].getY());
NpcHandler.npcs[player.npcClickIndex] NpcHandler.npcs[player.npcClickIndex]
.facePlayer(player.playerId); .facePlayer(player);
player.getNpcs().thirdClickNpc(player.npcType); player.getNpcs().thirdClickNpc(player.npcType);
player.post(new NpcThirdClickEvent(player.npcType)); player.post(new NpcThirdClickEvent(player.npcType));
container.stop(); container.stop();