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);
}
NpcHandler.npcs[i].facePlayer(player.playerId);
NpcHandler.npcs[i].facePlayer(player);
if (NpcHandler.npcs[i].underAttackBy > 0 && GameEngine.npcHandler.getsPulled(player, i)) {
NpcHandler.npcs[i].killerId = player.playerId;
} 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())) {
return;
}
NpcHandler.npcs[i].facePlayer(c.playerId);
NpcHandler.npcs[i].facePlayer(c);
boolean special = false;//specialCase(c,i);
if (NpcData.checkClip(NpcHandler.npcs[i]) || special) {
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].hitDelayTimer = NpcData.getHitDelay(i);
NpcHandler.npcs[i].attackType = 0;
@@ -428,7 +428,7 @@ public class DwarfCannon {
player.globalDamageDealt += damage;
target.killerId = player.playerId;
target.killedBy = player.playerId;
target.facePlayer(player.playerId);
target.facePlayer(player);
target.hitUpdateRequired2 = true;
target.updateRequired = true;
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 (!NpcHandler.npcs[i].underAttack) {
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.Stream;
import static com.rs2.game.content.StaticNpcList.*;
public class Npc {
public int npcId;
public int npcType;
public int absX, absY;
public int heightLevel;
public static int lastX, lastY;
public int makeX, makeY, maxHit, defence, attack, moveX, moveY, direction, walkingType, hitsToHeal;
public int spawnX, spawnY;
public int viewX, viewY;
public boolean summoner;
public int summonedBy, size;
public int focusPointX, focusPointY, masterId;
public boolean turnUpdateRequired;
public int chasingRat = -1;
public int npcId;
public int npcType;
public int absX, absY;
public int heightLevel;
public static int lastX, lastY;
public int makeX, makeY, maxHit, defence, attack, moveX, moveY, direction, walkingType, hitsToHeal;
public int spawnX, spawnY;
public int viewX, viewY;
public boolean summoner;
public int summonedBy, size;
public int focusPointX, focusPointY, masterId;
public boolean turnUpdateRequired;
public int chasingRat = -1;
/**
* attackType: 0 = melee, 1 = range, 2 = mage
*/
public int attackType, projectileId, endGfx, spawnedBy, hitDelayTimer, HP,
MaxHP, hitDiff, animNumber, actionTimer, enemyX, enemyY,
combatLevel;
public boolean applyDead, isDead, needRespawn, respawns, aggressive;
public boolean walkingHome, underAttack;
public int freezeTimer, attackTimer, killerId, killedBy, oldIndex,
underAttackBy;
public long lastDamageTaken;
public boolean randomWalk;
public boolean dirUpdateRequired;
public boolean animUpdateRequired;
public boolean hitUpdateRequired;
public boolean updateRequired;
public boolean forcedChatRequired;
public boolean faceToUpdateRequired;
public int firstAttacker;
public String forcedText;
public boolean transformUpdateRequired = false, isTransformed = false;
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() {
/**
* attackType: 0 = melee, 1 = range, 2 = mage
*/
public int attackType, projectileId, endGfx, spawnedBy, hitDelayTimer, HP,
MaxHP, hitDiff, animNumber, actionTimer, enemyX, enemyY,
combatLevel;
public boolean applyDead, isDead, needRespawn, respawns, aggressive;
public boolean walkingHome, underAttack;
public int freezeTimer, attackTimer, killerId, killedBy, oldIndex,
underAttackBy;
public long lastDamageTaken;
public boolean randomWalk;
public boolean dirUpdateRequired;
public boolean animUpdateRequired;
public boolean hitUpdateRequired;
public boolean updateRequired;
public boolean forcedChatRequired;
public boolean faceToUpdateRequired;
public int firstAttacker;
public String forcedText;
public boolean transformUpdateRequired = false, isTransformed = false;
public int transformId;
@Override
public void execute(CycleEventContainer container) {
requestTransform(currentId);
container.stop();
}
public Npc(int _npcId, int _npcType) {
npcId = _npcId;
npcType = _npcType;
direction = -1;
isDead = false;
applyDead = false;
actionTimer = 0;
randomWalk = true;
}
@Override
public void stop() {
NpcHandler.npcs[npcId].isTransformed = false;
}
}, transformTime);
}
public void appendTransformUpdate(Stream str) {
str.writeWordBigEndianA(transformId);
}
public void requestTransform(int id) {
transformId = id;
transformUpdateRequired = true;
updateRequired = true;
}
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) {
if (direction == -1) {
@Override
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);
str.writeBits(2, 0);
} 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 appendTransformUpdate(Stream str) {
str.writeWordBigEndianA(transformId);
}
/**
* Graphics
**/
public void updateNPCMovement(Stream str) {
public int mask80var1 = 0;
public int mask80var2 = 0;
protected boolean mask80update = false;
if (str != null) {
if (direction == -1) {
public void appendMask80Update(Stream str) {
str.writeWord(mask80var1);
str.writeDWord(mask80var2);
}
if (updateRequired) {
public void gfx100(int gfx) {
mask80var1 = gfx;
mask80var2 = 6553600;
mask80update = true;
updateRequired = true;
}
str.writeBits(1, 1);
str.writeBits(2, 0);
} else {
str.writeBits(1, 0);
}
} else {
public void gfx0(int gfx) {
mask80var1 = gfx;
mask80var2 = 65536;
mask80update = true;
updateRequired = true;
}
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);
}
}
}
}
public void appendAnimUpdate(Stream str) {
str.writeWordBigEndian(animNumber);
str.writeByte(1);
}
public int startAnimation(int anim, int npcId) {
return animNumber;
}
/**
* Text update
**/
/**
*
Face
**/
public void forceChat(String text) {
forcedText = text;
forcedChatRequired = true;
updateRequired = true;
}
public int FocusPointX = -1, FocusPointY = -1;
public int face = 0;
private void appendSetFocusDestination(Stream str) {
str.writeWordBigEndian(FocusPointX);
str.writeWordBigEndian(FocusPointY);
}
/**
* Graphics
**/
public void turnNpc(int i, int j) {
FocusPointX = 2 * i + 1;
FocusPointY = 2 * j + 1;
updateRequired = true;
turnUpdateRequired = true;
}
public int mask80var1 = 0;
public int mask80var2 = 0;
protected boolean mask80update = false;
public int getNextWalkingDirection2() {
int dir;
dir = Misc.direction(absX, absY, absX + moveX, absY + moveY);
dir >>= 1;
absX += moveX;
absY += moveY;
return dir;
}
public void appendMask80Update(Stream str) {
str.writeWord(mask80var1);
str.writeDWord(mask80var2);
}
public void getRandomAndHomeNPCWalking(int i) {
direction = -1;
if (NpcHandler.npcs[i].freezeTimer == 0) {
direction = getNextWalkingDirection2();
}
}
public void gfx100(int gfx) {
mask80var1 = gfx;
mask80var2 = 6553600;
mask80update = true;
updateRequired = true;
}
public void appendFaceEntity(Stream str) {
str.writeWord(face);
}
public void gfx0(int gfx) {
mask80var1 = gfx;
mask80var2 = 65536;
mask80update = true;
updateRequired = true;
}
public void facePlayer(int player) {
face = player + 32768;
dirUpdateRequired = true;
updateRequired = true;
}
public void appendAnimUpdate(Stream str) {
str.writeWordBigEndian(animNumber);
str.writeByte(1);
}
public void appendFaceToUpdate(Stream str) {
str.writeWordBigEndian(viewX);
str.writeWordBigEndian(viewY);
}
public int startAnimation(int anim, int npcId) {
return animNumber;
}
public void appendNPCUpdateBlock(Stream str) {
if (!updateRequired) {
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;
}
/**
* Face
**/
str.writeByte(updateMask);
public int FocusPointX = -1, FocusPointY = -1;
public int face = 0;
if (animUpdateRequired) {
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);
}
private void appendSetFocusDestination(Stream str) {
str.writeWordBigEndian(FocusPointX);
str.writeWordBigEndian(FocusPointY);
}
}
public void turnNpc(int i, int j) {
FocusPointX = 2 * i + 1;
FocusPointY = 2 * j + 1;
updateRequired = true;
turnUpdateRequired = true;
}
public void clearUpdateFlags() {
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 int getNextWalkingDirection2() {
int dir;
dir = Misc.direction(absX, absY, absX + moveX, absY + moveY);
dir >>= 1;
absX += moveX;
absY += moveY;
return dir;
}
public int getNextWalkingDirection() {
int nextX = absX + moveX;
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 getRandomAndHomeNPCWalking(int i) {
direction = -1;
if (NpcHandler.npcs[i].freezeTimer == 0) {
direction = getNextWalkingDirection2();
}
}
public void getNextNPCMovement(int i) {
direction = -1;
if (NpcHandler.npcs[i].freezeTimer == 0) {
direction = getNextWalkingDirection();
}
}
public void appendFaceEntity(Stream str) {
str.writeWord(face);
}
public void appendHitUpdate(Stream str) {
if (HP <= 0) {
isDead = true;
}
str.writeByteC(hitDiff);
if (hitDiff > 0) {
str.writeByteS(1);
} else {
str.writeByteS(0);
}
str.writeByteS(HP);
str.writeByteC(MaxHP);
}
/**
* NPC's That Don't Turn To Face The Player When Clicked
*/
private static int[] immobileNpcs = { //TODO Rename Appropriately
OSPAK,
STYRMIR,
TORBRUND,
FRIDGEIR,
};
public int hitDiff2 = 0;
public boolean hitUpdateRequired2 = false;
public void facePlayer(Player player) {
for (int element : immobileNpcs) {
if (npcType == (element)) {
return;
}
}
face = (player != null) ? player.playerId + 32768 : 32768;
dirUpdateRequired = true;
updateRequired = true;
}
public void appendHitUpdate2(Stream str) {
if (HP <= 0) {
isDead = true;
}
str.writeByteA(hitDiff2);
if (hitDiff2 > 0) {
str.writeByteC(1);
} else {
str.writeByteC(0);
}
str.writeByteA(HP);
str.writeByte(MaxHP);
}
public void appendFaceToUpdate(Stream str) {
str.writeWordBigEndian(viewX);
str.writeWordBigEndian(viewY);
}
public void handleHitMask(int damage) {
if (!hitUpdateRequired) {
hitUpdateRequired = true;
hitDiff = damage;
} else if (!hitUpdateRequired2) {
hitUpdateRequired2 = true;
hitDiff2 = damage;
}
updateRequired = true;
}
public void appendNPCUpdateBlock(Stream str) {
if (!updateRequired) {
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;
}
public int getX() {
return absX;
}
str.writeByte(updateMask);
public int getY() {
return absY;
}
if (animUpdateRequired) {
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() {
return lastY;
}
public void clearUpdateFlags() {
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) {
Npc.lastX = this.absX;
this.absX = absX;
}
public int getNextWalkingDirection() {
int nextX = absX + moveX;
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) {
Npc.lastY = this.absY;
this.absY = absY;
}
public void getNextNPCMovement(int i) {
direction = -1;
if (NpcHandler.npcs[i].freezeTimer == 0) {
direction = getNextWalkingDirection();
}
}
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 void appendHitUpdate(Stream str) {
if (HP <= 0) {
isDead = true;
}
str.writeByteC(hitDiff);
if (hitDiff > 0) {
str.writeByteS(1);
} else {
str.writeByteS(0);
}
str.writeByteS(HP);
str.writeByteC(MaxHP);
}
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 int hitDiff2 = 0;
public boolean hitUpdateRequired2 = 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;
}
public void appendHitUpdate2(Stream str) {
if (HP <= 0) {
isDead = true;
}
str.writeByteA(hitDiff2);
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.defence = defence;
newNPC.spawnedBy = c.getId();
newNPC.facePlayer(c.playerId);
newNPC.facePlayer(c);
if (headIcon) {
c.getPacketSender().drawHeadicon(1, slot, 0, 0);
}
@@ -461,7 +461,7 @@ public class NpcHandler {
if (slaveOwner != null && slaveOwner.hasNpc && npcs[i].summoner) {
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;
if (PlayerHandler.players[p] != null) {
Player c = (Client) PlayerHandler.players[p];
followPlayer(i, c.playerId);
followPlayer(i, c);
if (npcs[i] == null) {
continue;
}
@@ -598,7 +598,7 @@ public class NpcHandler {
} else {
npcs[i].killerId = 0;
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)
&& npcs[i].randomWalk && !npcs[i].isDead) {
npcs[i].facePlayer(0);
npcs[i].facePlayer(null);
npcs[i].killerId = 0;
if (npcs[i].spawnedBy == 0) {
if (npcs[i].absX > npcs[i].makeX
@@ -730,7 +730,7 @@ public class NpcHandler {
if (npcs[i].isDead) {
if (npcs[i].actionTimer == 0 && npcs[i].applyDead == false && npcs[i].needRespawn == false) {
npcs[i].updateRequired = true;
npcs[i].facePlayer(0);
npcs[i].facePlayer(null);
npcs[i].killedBy = NpcData.getNpcKillerId(i);
Player c = (Client) PlayerHandler.players[npcs[i].killedBy];
if (c != null) {
@@ -1197,15 +1197,15 @@ public class NpcHandler {
return true;
}
public static void followPlayer(int i, int playerId) {
if (PlayerHandler.players[playerId] == null) {
public static void followPlayer(int i, Player player) {
if (player == null) {
return;
}
if (PlayerHandler.players[playerId].npcCanAttack == false) {
if (player.npcCanAttack == false) {
return;
}
if (PlayerHandler.players[playerId].respawnTimer > 0) {
npcs[i].facePlayer(0);
if (player.respawnTimer > 0) {
npcs[i].facePlayer(null);
npcs[i].randomWalk = true;
npcs[i].underAttack = false;
return;
@@ -1216,12 +1216,12 @@ public class NpcHandler {
}
if (!followPlayer(i) && npcs[i].npcType != 1532 && npcs[i].npcType != 1534) {
npcs[i].facePlayer(playerId);
npcs[i].facePlayer(player);
return;
}
int playerX = PlayerHandler.players[playerId].absX;
int playerY = PlayerHandler.players[playerId].absY;
int playerX = player.absX;
int playerY = player.absY;
npcs[i].randomWalk = false;
if (goodDistance(npcs[i].getX(), npcs[i].getY(), playerX, playerY, distanceRequired(i))) {
return;
@@ -1230,7 +1230,6 @@ public class NpcHandler {
Npc npc = npcs[i];
int x = npc.absX;
int y = npc.absY;
Player player = PlayerHandler.players[playerId];
if (npcs[i].spawnedBy > 0
|| 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.moveY = GetMove(y, playerY);
}
npc.facePlayer(playerId);
npc.facePlayer(player);
handleClipping(i);
npc.getRandomAndHomeNPCWalking(i);
npc.updateRequired = true;
}
}
} else {
npc.facePlayer(0);
npc.facePlayer(null);
npc.randomWalk = true;
npc.underAttack = false;
}
@@ -239,7 +239,7 @@ public class ClickNPC implements PacketType {
player.getY(), 2)) {
player.turnPlayerTo(NpcHandler.npcs[player.npcClickIndex].getX(),
NpcHandler.npcs[player.npcClickIndex].getY());
NpcHandler.npcs[player.npcClickIndex].facePlayer(player.playerId);
NpcHandler.npcs[player.npcClickIndex].facePlayer(player);
player.getNpcs().firstClickNpc(player.npcType);
player.post(new NpcFirstClickEvent(player.npcType));
} else {
@@ -256,7 +256,7 @@ public class ClickNPC implements PacketType {
NpcHandler.npcs[player.npcClickIndex].getX(),
NpcHandler.npcs[player.npcClickIndex].getY());
NpcHandler.npcs[player.npcClickIndex]
.facePlayer(player.playerId);
.facePlayer(player);
player.getNpcs().firstClickNpc(player.npcType);
player.post(new NpcFirstClickEvent(player.npcType));
container.stop();
@@ -282,7 +282,7 @@ public class ClickNPC implements PacketType {
player.getY(), 2)) {
player.turnPlayerTo(NpcHandler.npcs[player.npcClickIndex].getX(),
NpcHandler.npcs[player.npcClickIndex].getY());
NpcHandler.npcs[player.npcClickIndex].facePlayer(player.playerId);
NpcHandler.npcs[player.npcClickIndex].facePlayer(player);
player.getNpcs().secondClickNpc(player.npcType);
player.post(new NpcSecondClickEvent(player.npcType));
} else {
@@ -299,7 +299,7 @@ public class ClickNPC implements PacketType {
NpcHandler.npcs[player.npcClickIndex].getX(),
NpcHandler.npcs[player.npcClickIndex].getY());
NpcHandler.npcs[player.npcClickIndex]
.facePlayer(player.playerId);
.facePlayer(player);
player.getNpcs().secondClickNpc(player.npcType);
player.post(new NpcSecondClickEvent(player.npcType));
container.stop();
@@ -326,7 +326,7 @@ public class ClickNPC implements PacketType {
player.getY(), 2)) {
player.turnPlayerTo(NpcHandler.npcs[player.npcClickIndex].getX(),
NpcHandler.npcs[player.npcClickIndex].getY());
NpcHandler.npcs[player.npcClickIndex].facePlayer(player.playerId);
NpcHandler.npcs[player.npcClickIndex].facePlayer(player);
player.getNpcs().thirdClickNpc(player.npcType);
player.post(new NpcThirdClickEvent(player.npcType));
} else {
@@ -343,7 +343,7 @@ public class ClickNPC implements PacketType {
NpcHandler.npcs[player.npcClickIndex].getX(),
NpcHandler.npcs[player.npcClickIndex].getY());
NpcHandler.npcs[player.npcClickIndex]
.facePlayer(player.playerId);
.facePlayer(player);
player.getNpcs().thirdClickNpc(player.npcType);
player.post(new NpcThirdClickEvent(player.npcType));
container.stop();