Skip to content

Commit d2fe8b0

Browse files
authored
Refactoring follow player/NPC variables and NPC magic numbers (#659)
* 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
1 parent 20ccc23 commit d2fe8b0

File tree

14 files changed

+305
-428
lines changed

14 files changed

+305
-428
lines changed

2006Scape Server/src/main/java/com/rs2/game/content/combat/CombatAssistant.java

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import com.rs2.world.Boundary;
3131
import com.rs2.world.clip.PathFinder;
3232

33+
import static com.rs2.game.content.StaticNpcList.*;
34+
3335
/**
3436
* @author whoever contributed
3537
* @author Andrew (Mr Extremez)
@@ -89,7 +91,7 @@ public void delayedHit(int i) { // npc hit delay
8991
NpcHandler.npcs[i].gfx0(758);
9092
}
9193
if (Misc.random(NpcHandler.npcs[i].defence) > Misc.random(10 + calculateRangeAttack()) && !ignoreDef
92-
|| (NpcHandler.npcs[i].npcType == 2881 || NpcHandler.npcs[i].npcType == 2883 && !ignoreDef)) {
94+
|| (NpcHandler.npcs[i].npcType == DAGANNOTH_SUPREME || NpcHandler.npcs[i].npcType == DAGANNOTH_REX && !ignoreDef)) {
9395
damage = 0;
9496
}
9597
if (Misc.random(4) == 1 && player.lastArrowUsed == 9242 && damage > 0) {
@@ -182,7 +184,7 @@ public void delayedHit(int i) { // npc hit delay
182184
if (Misc.random(NpcHandler.npcs[i].defence) > 10 + Misc.random(mageAtk()) + bonusAttack) {
183185
damage = 0;
184186
magicFailed = true;
185-
} else if (NpcHandler.npcs[i].npcType == 2881 || NpcHandler.npcs[i].npcType == 2882) {
187+
} else if (NpcHandler.npcs[i].npcType == DAGANNOTH_SUPREME || NpcHandler.npcs[i].npcType == DAGANNOTH_PRIME) {
186188
damage = 0;
187189
magicFailed = true;
188190
}
@@ -278,7 +280,7 @@ public void applyNpcMeleeDamage(int i, int damageMask) {
278280
if (!fullVeracsEffect) {
279281
if (Misc.random(NpcHandler.npcs[i].defence) > 10 + Misc.random(calcAtt())) {
280282
damage = 0;
281-
} else if (NpcHandler.npcs[i].npcType == 2882 || NpcHandler.npcs[i].npcType == 2883) {
283+
} else if (NpcHandler.npcs[i].npcType == DAGANNOTH_PRIME || NpcHandler.npcs[i].npcType == DAGANNOTH_REX) {
282284
damage = 0;
283285
}
284286
}
@@ -296,7 +298,7 @@ public void applyNpcMeleeDamage(int i, int damageMask) {
296298
guthansEffect = true;
297299
}
298300
}
299-
if (player.fightMode == 3 && NpcHandler.npcs[i].npcType != 2459 && NpcHandler.npcs[i].npcType != 2460 && NpcHandler.npcs[i].npcType != 2461 && NpcHandler.npcs[i].npcType != 2462) {
301+
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) {
300302
player.getPlayerAssistant().addSkillXP(damage * CombatConstants.MELEE_EXP_RATE / 3, 0);
301303
player.getPlayerAssistant().addSkillXP(damage * CombatConstants.MELEE_EXP_RATE / 3, 1);
302304
player.getPlayerAssistant().addSkillXP(damage * CombatConstants.MELEE_EXP_RATE / 3, 2);
@@ -306,7 +308,7 @@ public void applyNpcMeleeDamage(int i, int damageMask) {
306308
player.getPlayerAssistant().refreshSkill(Constants.STRENGTH);
307309
player.getPlayerAssistant().refreshSkill(Constants.HITPOINTS);
308310
} else {
309-
if (NpcHandler.npcs[i].npcType != 2459 && NpcHandler.npcs[i].npcType != 2460 && NpcHandler.npcs[i].npcType != 2461 && NpcHandler.npcs[i].npcType != 2462) {
311+
if (NpcHandler.npcs[i].npcType != PHEASANT && NpcHandler.npcs[i].npcType != PHEASANT_2460 && NpcHandler.npcs[i].npcType != PHEASANT_2461 && NpcHandler.npcs[i].npcType != PHEASANT_2462) {
310312
player.getPlayerAssistant().addSkillXP(damage * CombatConstants.MELEE_EXP_RATE, player.fightMode);
311313
player.getPlayerAssistant().addSkillXP(damage * CombatConstants.MELEE_EXP_RATE / 3, 3);
312314
player.getPlayerAssistant().refreshSkill(player.fightMode);
@@ -385,7 +387,7 @@ public void attackingNpcTick() {
385387
if (i > 0 && NpcHandler.npcs[i] != null) {
386388
if (NpcHandler.npcs[i].isDead) {
387389
player.npcIndex = 0;
388-
player.followId2 = 0;
390+
player.followNpcId = 0;
389391
player.faceNpc(0);
390392
return;
391393
}
@@ -411,7 +413,7 @@ public void attackingNpcTick() {
411413
return;
412414
} else {
413415
if (player.usingMagic || player.usingBow || player.usingRangeWeapon) {
414-
player.followId2 = 0;
416+
player.followNpcId = 0;
415417
}
416418
player.stopMovement();
417419
}
@@ -423,7 +425,7 @@ public void attackingPlayerTick() {
423425
if (i > 0 && PlayerHandler.players[i] != null) {
424426
if (PlayerHandler.players[i].isDead) {
425427
player.playerIndex = 0;
426-
player.followId = 0;
428+
player.followPlayerId = 0;
427429
player.faceNpc(0);
428430
return;
429431
}
@@ -447,7 +449,7 @@ public void attackingPlayerTick() {
447449
return;
448450
} else {
449451
if (player.usingMagic || player.usingBow || player.usingRangeWeapon) {
450-
player.followId = 0;
452+
player.followPlayerId = 0;
451453
}
452454
player.stopMovement();
453455
}
@@ -479,7 +481,7 @@ public void attackNpc(int i) {
479481
if (!SlayerRequirements.itemNeededSlayer(player, i) || !player.getSlayer().canAttackNpc(i)) {
480482
return;
481483
}
482-
if (NpcHandler.npcs[i].npcType == 757 && player.vampSlayer > 2) {
484+
if (NpcHandler.npcs[i].npcType == COUNT_DRAYNOR && player.vampSlayer > 2) {
483485
if (!player.getItemAssistant().playerHasItem(1549, 1) || !player.getItemAssistant().playerHasItem(2347, 1)) {
484486
player.getPacketSender().sendMessage("You need a stake and hammer to attack count draynor.");
485487
resetPlayerAttack();
@@ -491,12 +493,12 @@ public void attackNpc(int i) {
491493
resetPlayerAttack();
492494
return;
493495
}
494-
if (NpcHandler.npcs[i].npcType == 1676) {
496+
if (NpcHandler.npcs[i].npcType == EXPERIMENT) {
495497
player.getPacketSender().sendMessage("You don't have the heart to kill the poor creature again.");
496498
resetPlayerAttack();
497499
return;
498500
}
499-
if (NpcHandler.npcs[i].npcType == 411) {
501+
if (NpcHandler.npcs[i].npcType == SWARM) {
500502
player.getPacketSender().sendMessage("You can't attack a swarm!");
501503
resetPlayerAttack();
502504
return;
@@ -517,8 +519,8 @@ public void attackNpc(int i) {
517519
return;
518520
}
519521

520-
player.followId2 = i;
521-
player.followId = 0;
522+
player.followNpcId = i;
523+
player.followPlayerId = 0;
522524
if (player.attackTimer <= 0) {
523525
player.usingBow = false;
524526
player.usingRangeWeapon = false;
@@ -573,7 +575,7 @@ public void attackNpc(int i) {
573575
return;
574576
} else {
575577
if (player.usingMagic || player.usingBow || player.usingRangeWeapon) {
576-
player.followId2 = 0;
578+
player.followNpcId = 0;
577579
}
578580
player.stopMovement();
579581
}
@@ -803,7 +805,7 @@ public void attackPlayer(int i) {
803805
resetPlayerAttack();
804806
return;
805807
}
806-
player.followId = i;
808+
player.followPlayerId = i;
807809
player.attackTimer = 0;
808810
return;
809811
}
@@ -876,7 +878,7 @@ public void attackPlayer(int i) {
876878
return;
877879
} else {
878880
if (player.usingMagic || player.usingBow || player.usingRangeWeapon) {
879-
player.followId = 0;
881+
player.followPlayerId = 0;
880882
}
881883
}
882884

@@ -950,7 +952,7 @@ public void attackPlayer(int i) {
950952
if (checkSpecAmount(equippedWeapon)) {
951953
player.lastArrowUsed = player.playerEquipment[player.playerArrows];
952954
player.getSpecials().activateSpecial(player.playerEquipment[player.playerWeapon], o, i);
953-
player.followId = player.playerIndex;
955+
player.followPlayerId = player.playerIndex;
954956
return;
955957
} else {
956958
player.getPacketSender().sendMessage("You don't have the required special energy to use this attack.");
@@ -985,7 +987,7 @@ public void attackPlayer(int i) {
985987
player.lastArrowUsed = 0;
986988
player.rangeItemUsed = 0;
987989
if (!player.usingBow && !player.usingMagic && !player.usingRangeWeapon) { // melee hit delay
988-
player.followId = PlayerHandler.players[player.playerIndex].playerId;
990+
player.followPlayerId = PlayerHandler.players[player.playerIndex].playerId;
989991
player.hitDelay = getHitDelay();
990992
player.delayedDamage = Misc.random(meleeMaxHit());
991993
player.projectileStage = 0;
@@ -1006,7 +1008,7 @@ public void attackPlayer(int i) {
10061008
player.usingBow = true;
10071009
}
10081010
player.usingBow = true;
1009-
player.followId = PlayerHandler.players[player.playerIndex].playerId;
1011+
player.followPlayerId = PlayerHandler.players[player.playerIndex].playerId;
10101012
player.lastWeaponUsed = player.playerEquipment[player.playerWeapon];
10111013
player.lastArrowUsed = player.playerEquipment[player.playerArrows];
10121014
player.gfx100(RangeData.getRangeStartGFX(player));
@@ -1019,7 +1021,7 @@ public void attackPlayer(int i) {
10191021
player.rangeItemUsed = player.playerEquipment[player.playerWeapon];
10201022
player.getItemAssistant().deleteEquipment();
10211023
player.usingRangeWeapon = true;
1022-
player.followId = PlayerHandler.players[player.playerIndex].playerId;
1024+
player.followPlayerId = PlayerHandler.players[player.playerIndex].playerId;
10231025
player.gfx100(RangeData.getRangeStartGFX(player));
10241026
if (player.fightMode == 2) {
10251027
player.attackTimer--;
@@ -1694,7 +1696,7 @@ public boolean checkReqs() {
16941696
}
16951697

16961698
public int getRequiredDistance() {
1697-
if (player.followId > 0 && player.freezeTimer <= 0) {
1699+
if (player.followPlayerId > 0 && player.freezeTimer <= 0) {
16981700
return player.isMoving ? 3 : 2;
16991701
}
17001702
return 1;
@@ -1743,14 +1745,14 @@ public void removeRecoil(Player c2) {
17431745

17441746
public int getBonusAttack(int i) {
17451747
switch (NpcHandler.npcs[i].npcType) {
1746-
case 2883:
1747-
return Misc.random(50) + 30;
1748-
case 2026:
1749-
case 2027:
1750-
case 2029:
1751-
case 2030:
1752-
return Misc.random(50) + 30;
1753-
}
1748+
case DAGANNOTH_REX:
1749+
return Misc.random(50) + 30;
1750+
case DHAROK_THE_WRETCHED:
1751+
case GUTHAN_THE_INFESTED:
1752+
case TORAG_THE_CORRUPTED:
1753+
case VERAC_THE_DEFILED:
1754+
return Misc.random(50) + 30;
1755+
}
17541756
return 0;
17551757
}
17561758

0 commit comments

Comments
 (0)