Skip to content

Commit

Permalink
Refactoring follow player/NPC variables and NPC magic numbers (#659)
Browse files Browse the repository at this point in the history
* Refactoring follow player/NPC variables

* Magic number refactoring

* Added more NPC refactoring

* More NPC refactoring

* More refactoring and removed GWD NPCs

GWD was added in 2007, not 2006, so there's absolutely no reason why this code should exist in the server.

* Removed more GWD NPCs

* Refactored remaining NPC IDs
  • Loading branch information
ipkpjersi authored Dec 6, 2024
1 parent 20ccc23 commit d2fe8b0
Show file tree
Hide file tree
Showing 14 changed files with 305 additions and 428 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import com.rs2.world.Boundary;
import com.rs2.world.clip.PathFinder;

import static com.rs2.game.content.StaticNpcList.*;

/**
* @author whoever contributed
* @author Andrew (Mr Extremez)
Expand Down Expand Up @@ -89,7 +91,7 @@ public void delayedHit(int i) { // npc hit delay
NpcHandler.npcs[i].gfx0(758);
}
if (Misc.random(NpcHandler.npcs[i].defence) > Misc.random(10 + calculateRangeAttack()) && !ignoreDef
|| (NpcHandler.npcs[i].npcType == 2881 || NpcHandler.npcs[i].npcType == 2883 && !ignoreDef)) {
|| (NpcHandler.npcs[i].npcType == DAGANNOTH_SUPREME || NpcHandler.npcs[i].npcType == DAGANNOTH_REX && !ignoreDef)) {
damage = 0;
}
if (Misc.random(4) == 1 && player.lastArrowUsed == 9242 && damage > 0) {
Expand Down Expand Up @@ -182,7 +184,7 @@ public void delayedHit(int i) { // npc hit delay
if (Misc.random(NpcHandler.npcs[i].defence) > 10 + Misc.random(mageAtk()) + bonusAttack) {
damage = 0;
magicFailed = true;
} else if (NpcHandler.npcs[i].npcType == 2881 || NpcHandler.npcs[i].npcType == 2882) {
} else if (NpcHandler.npcs[i].npcType == DAGANNOTH_SUPREME || NpcHandler.npcs[i].npcType == DAGANNOTH_PRIME) {
damage = 0;
magicFailed = true;
}
Expand Down Expand Up @@ -278,7 +280,7 @@ public void applyNpcMeleeDamage(int i, int damageMask) {
if (!fullVeracsEffect) {
if (Misc.random(NpcHandler.npcs[i].defence) > 10 + Misc.random(calcAtt())) {
damage = 0;
} else if (NpcHandler.npcs[i].npcType == 2882 || NpcHandler.npcs[i].npcType == 2883) {
} else if (NpcHandler.npcs[i].npcType == DAGANNOTH_PRIME || NpcHandler.npcs[i].npcType == DAGANNOTH_REX) {
damage = 0;
}
}
Expand All @@ -296,7 +298,7 @@ public void applyNpcMeleeDamage(int i, int damageMask) {
guthansEffect = true;
}
}
if (player.fightMode == 3 && NpcHandler.npcs[i].npcType != 2459 && NpcHandler.npcs[i].npcType != 2460 && NpcHandler.npcs[i].npcType != 2461 && NpcHandler.npcs[i].npcType != 2462) {
if (player.fightMode == 3 && NpcHandler.npcs[i].npcType != PHEASANT && NpcHandler.npcs[i].npcType != PHEASANT_2460 && NpcHandler.npcs[i].npcType != PHEASANT_2461 && NpcHandler.npcs[i].npcType != PHEASANT_2462) {
player.getPlayerAssistant().addSkillXP(damage * CombatConstants.MELEE_EXP_RATE / 3, 0);
player.getPlayerAssistant().addSkillXP(damage * CombatConstants.MELEE_EXP_RATE / 3, 1);
player.getPlayerAssistant().addSkillXP(damage * CombatConstants.MELEE_EXP_RATE / 3, 2);
Expand All @@ -306,7 +308,7 @@ public void applyNpcMeleeDamage(int i, int damageMask) {
player.getPlayerAssistant().refreshSkill(Constants.STRENGTH);
player.getPlayerAssistant().refreshSkill(Constants.HITPOINTS);
} else {
if (NpcHandler.npcs[i].npcType != 2459 && NpcHandler.npcs[i].npcType != 2460 && NpcHandler.npcs[i].npcType != 2461 && NpcHandler.npcs[i].npcType != 2462) {
if (NpcHandler.npcs[i].npcType != PHEASANT && NpcHandler.npcs[i].npcType != PHEASANT_2460 && NpcHandler.npcs[i].npcType != PHEASANT_2461 && NpcHandler.npcs[i].npcType != PHEASANT_2462) {
player.getPlayerAssistant().addSkillXP(damage * CombatConstants.MELEE_EXP_RATE, player.fightMode);
player.getPlayerAssistant().addSkillXP(damage * CombatConstants.MELEE_EXP_RATE / 3, 3);
player.getPlayerAssistant().refreshSkill(player.fightMode);
Expand Down Expand Up @@ -385,7 +387,7 @@ public void attackingNpcTick() {
if (i > 0 && NpcHandler.npcs[i] != null) {
if (NpcHandler.npcs[i].isDead) {
player.npcIndex = 0;
player.followId2 = 0;
player.followNpcId = 0;
player.faceNpc(0);
return;
}
Expand All @@ -411,7 +413,7 @@ public void attackingNpcTick() {
return;
} else {
if (player.usingMagic || player.usingBow || player.usingRangeWeapon) {
player.followId2 = 0;
player.followNpcId = 0;
}
player.stopMovement();
}
Expand All @@ -423,7 +425,7 @@ public void attackingPlayerTick() {
if (i > 0 && PlayerHandler.players[i] != null) {
if (PlayerHandler.players[i].isDead) {
player.playerIndex = 0;
player.followId = 0;
player.followPlayerId = 0;
player.faceNpc(0);
return;
}
Expand All @@ -447,7 +449,7 @@ public void attackingPlayerTick() {
return;
} else {
if (player.usingMagic || player.usingBow || player.usingRangeWeapon) {
player.followId = 0;
player.followPlayerId = 0;
}
player.stopMovement();
}
Expand Down Expand Up @@ -479,7 +481,7 @@ public void attackNpc(int i) {
if (!SlayerRequirements.itemNeededSlayer(player, i) || !player.getSlayer().canAttackNpc(i)) {
return;
}
if (NpcHandler.npcs[i].npcType == 757 && player.vampSlayer > 2) {
if (NpcHandler.npcs[i].npcType == COUNT_DRAYNOR && player.vampSlayer > 2) {
if (!player.getItemAssistant().playerHasItem(1549, 1) || !player.getItemAssistant().playerHasItem(2347, 1)) {
player.getPacketSender().sendMessage("You need a stake and hammer to attack count draynor.");
resetPlayerAttack();
Expand All @@ -491,12 +493,12 @@ public void attackNpc(int i) {
resetPlayerAttack();
return;
}
if (NpcHandler.npcs[i].npcType == 1676) {
if (NpcHandler.npcs[i].npcType == EXPERIMENT) {
player.getPacketSender().sendMessage("You don't have the heart to kill the poor creature again.");
resetPlayerAttack();
return;
}
if (NpcHandler.npcs[i].npcType == 411) {
if (NpcHandler.npcs[i].npcType == SWARM) {
player.getPacketSender().sendMessage("You can't attack a swarm!");
resetPlayerAttack();
return;
Expand All @@ -517,8 +519,8 @@ public void attackNpc(int i) {
return;
}

player.followId2 = i;
player.followId = 0;
player.followNpcId = i;
player.followPlayerId = 0;
if (player.attackTimer <= 0) {
player.usingBow = false;
player.usingRangeWeapon = false;
Expand Down Expand Up @@ -573,7 +575,7 @@ public void attackNpc(int i) {
return;
} else {
if (player.usingMagic || player.usingBow || player.usingRangeWeapon) {
player.followId2 = 0;
player.followNpcId = 0;
}
player.stopMovement();
}
Expand Down Expand Up @@ -803,7 +805,7 @@ public void attackPlayer(int i) {
resetPlayerAttack();
return;
}
player.followId = i;
player.followPlayerId = i;
player.attackTimer = 0;
return;
}
Expand Down Expand Up @@ -876,7 +878,7 @@ public void attackPlayer(int i) {
return;
} else {
if (player.usingMagic || player.usingBow || player.usingRangeWeapon) {
player.followId = 0;
player.followPlayerId = 0;
}
}

Expand Down Expand Up @@ -950,7 +952,7 @@ public void attackPlayer(int i) {
if (checkSpecAmount(equippedWeapon)) {
player.lastArrowUsed = player.playerEquipment[player.playerArrows];
player.getSpecials().activateSpecial(player.playerEquipment[player.playerWeapon], o, i);
player.followId = player.playerIndex;
player.followPlayerId = player.playerIndex;
return;
} else {
player.getPacketSender().sendMessage("You don't have the required special energy to use this attack.");
Expand Down Expand Up @@ -985,7 +987,7 @@ public void attackPlayer(int i) {
player.lastArrowUsed = 0;
player.rangeItemUsed = 0;
if (!player.usingBow && !player.usingMagic && !player.usingRangeWeapon) { // melee hit delay
player.followId = PlayerHandler.players[player.playerIndex].playerId;
player.followPlayerId = PlayerHandler.players[player.playerIndex].playerId;
player.hitDelay = getHitDelay();
player.delayedDamage = Misc.random(meleeMaxHit());
player.projectileStage = 0;
Expand All @@ -1006,7 +1008,7 @@ public void attackPlayer(int i) {
player.usingBow = true;
}
player.usingBow = true;
player.followId = PlayerHandler.players[player.playerIndex].playerId;
player.followPlayerId = PlayerHandler.players[player.playerIndex].playerId;
player.lastWeaponUsed = player.playerEquipment[player.playerWeapon];
player.lastArrowUsed = player.playerEquipment[player.playerArrows];
player.gfx100(RangeData.getRangeStartGFX(player));
Expand All @@ -1019,7 +1021,7 @@ public void attackPlayer(int i) {
player.rangeItemUsed = player.playerEquipment[player.playerWeapon];
player.getItemAssistant().deleteEquipment();
player.usingRangeWeapon = true;
player.followId = PlayerHandler.players[player.playerIndex].playerId;
player.followPlayerId = PlayerHandler.players[player.playerIndex].playerId;
player.gfx100(RangeData.getRangeStartGFX(player));
if (player.fightMode == 2) {
player.attackTimer--;
Expand Down Expand Up @@ -1694,7 +1696,7 @@ public boolean checkReqs() {
}

public int getRequiredDistance() {
if (player.followId > 0 && player.freezeTimer <= 0) {
if (player.followPlayerId > 0 && player.freezeTimer <= 0) {
return player.isMoving ? 3 : 2;
}
return 1;
Expand Down Expand Up @@ -1743,14 +1745,14 @@ public void removeRecoil(Player c2) {

public int getBonusAttack(int i) {
switch (NpcHandler.npcs[i].npcType) {
case 2883:
return Misc.random(50) + 30;
case 2026:
case 2027:
case 2029:
case 2030:
return Misc.random(50) + 30;
}
case DAGANNOTH_REX:
return Misc.random(50) + 30;
case DHAROK_THE_WRETCHED:
case GUTHAN_THE_INFESTED:
case TORAG_THE_CORRUPTED:
case VERAC_THE_DEFILED:
return Misc.random(50) + 30;
}
return 0;
}

Expand Down
Loading

0 comments on commit d2fe8b0

Please sign in to comment.