Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added NPC kill counts with message display #644

Merged
merged 16 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions 2006Scape Server/src/main/java/com/rs2/Constants.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.rs2;

import com.rs2.game.content.StaticNpcList;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;

public class Constants {

Expand Down Expand Up @@ -105,4 +110,89 @@ public class Constants {
CRAFTING = 12, SMITHING = 13, MINING = 14, HERBLORE = 15,
AGILITY = 16, THIEVING = 17, SLAYER = 18, FARMING = 19,
RUNECRAFTING = 20;

public static final LinkedHashSet<Integer> BOSS_NPC_IDS = new LinkedHashSet<>(Arrays.asList(
StaticNpcList.CHAOS_ELEMENTAL,
StaticNpcList.DAGANNOTH_REX,
StaticNpcList.DAGANNOTH_PRIME,
StaticNpcList.DAGANNOTH_SUPREME,
StaticNpcList.GIANT_MOLE,
StaticNpcList.KING_BLACK_DRAGON,
StaticNpcList.KALPHITE_QUEEN,
StaticNpcList.TZTOKJAD
));

public static final LinkedHashSet<Integer> SLAYER_NPC_IDS = new LinkedHashSet<>(Arrays.asList(
StaticNpcList.CRAWLING_HAND,
StaticNpcList.CRAWLING_HAND_1649,
StaticNpcList.CRAWLING_HAND_1650,
StaticNpcList.CRAWLING_HAND_1651,
StaticNpcList.CRAWLING_HAND_1652,
StaticNpcList.CRAWLING_HAND_1653,
StaticNpcList.CRAWLING_HAND_1654,
StaticNpcList.CRAWLING_HAND_1655,
StaticNpcList.CRAWLING_HAND_1656,
StaticNpcList.CRAWLING_HAND_1657,
StaticNpcList.CAVE_BUG,
StaticNpcList.CAVE_CRAWLER,
StaticNpcList.CAVE_CRAWLER_1601,
StaticNpcList.CAVE_CRAWLER_1602,
StaticNpcList.CAVE_CRAWLER_1603,
StaticNpcList.BANSHEE,
StaticNpcList.CAVE_SLIME,
StaticNpcList.ROCKSLUG,
StaticNpcList.ROCKSLUG_1623,
StaticNpcList.DESERT_LIZARD,
StaticNpcList.DESERT_LIZARD_2805,
StaticNpcList.DESERT_LIZARD_2806,
StaticNpcList.COCKATRICE,
StaticNpcList.COCKATRICE_1621,
StaticNpcList.PYREFIEND,
StaticNpcList.PYREFIEND_1634,
StaticNpcList.PYREFIEND_1635,
StaticNpcList.PYREFIEND_1636,
StaticNpcList.MOGRE,
StaticNpcList.HARPIE_BUG_SWARM,
StaticNpcList.WALL_BEAST,
StaticNpcList.KILLERWATT,
StaticNpcList.KILLERWATT_3202,
StaticNpcList.BASILISK,
StaticNpcList.BASILISK_1617,
StaticNpcList.FEVER_SPIDER,
StaticNpcList.INFERNAL_MAGE,
StaticNpcList.INFERNAL_MAGE_1644,
StaticNpcList.INFERNAL_MAGE_1645,
StaticNpcList.INFERNAL_MAGE_1646,
StaticNpcList.INFERNAL_MAGE_1647,
StaticNpcList.JELLY,
StaticNpcList.JELLY_1638,
StaticNpcList.JELLY_1639,
StaticNpcList.JELLY_1640,
StaticNpcList.JELLY_1641,
StaticNpcList.JELLY_1642,
StaticNpcList.TUROTH,
StaticNpcList.TUROTH_1627,
StaticNpcList.TUROTH_1628,
StaticNpcList.TUROTH_1629,
StaticNpcList.TUROTH_1630,
StaticNpcList.TUROTH_1631,
StaticNpcList.TUROTH_1632,
StaticNpcList.ABERRANT_SPECTER,
StaticNpcList.ABERRANT_SPECTER_1605,
StaticNpcList.ABERRANT_SPECTER_1606,
StaticNpcList.ABERRANT_SPECTER_1607,
StaticNpcList.DUST_DEVIL,
StaticNpcList.KURASK,
StaticNpcList.KURASK_1609,
StaticNpcList.SKELETAL_WYVERN,
StaticNpcList.SKELETAL_WYVERN_3069,
StaticNpcList.SKELETAL_WYVERN_3070,
StaticNpcList.SKELETAL_WYVERN_3071,
StaticNpcList.GARGOYLE,
StaticNpcList.GARGOYLE_1611,
StaticNpcList.NECHRYAEL,
StaticNpcList.ABYSSAL_DEMON,
StaticNpcList.DARK_BEAST,
StaticNpcList.SMOKEDEVIL
));
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ public void useChest() {
}
if (c.barrowsKillCount > 5 && checkBarrows()) {
if (c.getItemAssistant().freeSlots() >= 4) {
c.incrementNpcKillCount(100000, 1);
if (c.displayBossKcMessages || c.displayRegularKcMessages) {
c.getPacketSender().sendMessage("Your Barrows Chest count is now: " + c.getNpcKillCount(100000));
}
reward();
resetBarrows();
} else {
Expand Down
4 changes: 4 additions & 0 deletions 2006Scape Server/src/main/java/com/rs2/game/npcs/Npc.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public void requestTransform(int id) {
transformUpdateRequired = true;
updateRequired = true;
}

public String name() {
return NpcHandler.getNpcListName(this.npcType);
}

public void shearSheep(Player player, int itemNeeded, int itemGiven, int animation, final int currentId, final int newId, int transformTime) {
if (!player.getItemAssistant().playerHasItem(itemNeeded)) {
Expand Down
20 changes: 16 additions & 4 deletions 2006Scape Server/src/main/java/com/rs2/game/npcs/NpcHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,28 +331,34 @@ public void spawnNpc2(int npcType, int x, int y, int heightLevel, int WalkingTyp
npcs[slot] = newNPC;
}

private void killedBarrow(int i) {
private boolean killedBarrow(int i) {
boolean barrows = false;
Player c = (Client) PlayerHandler.players[npcs[i].killedBy];
if (c != null) {
for (int o = 0; o < c.barrowsNpcs.length; o++) {
if (npcs[i].npcType == c.barrowsNpcs[o][0]) {
c.barrowsNpcs[o][1] = 2; // 2 for dead
c.barrowsKillCount++;
barrows = true;
}
}
}
return barrows;
}

private void killedCrypt(int i) {
private boolean killedCrypt(int i) {
boolean crypt = false;
Player c = (Client) PlayerHandler.players[npcs[i].killedBy];
if (c != null) {
for (int o = 0; o < c.barrowCrypt.length; o++) {
if (npcs[i].npcType == c.barrowCrypt[o][0]) {
c.barrowsKillCount++;
c.getPacketSender().sendString("" + c.barrowsKillCount, 4536);
crypt = true;
}
}
}
return crypt;
}

public void newNPC(int npcType, int x, int y, int heightLevel,
Expand Down Expand Up @@ -745,10 +751,16 @@ else if (rand <= 20)
npcs[i].animUpdateRequired = true;
npcs[i].freezeTimer = 0;
npcs[i].applyDead = true;
killedBarrow(i);
killedCrypt(i);
boolean barrows = killedBarrow(i);
boolean crypt = killedCrypt(i);
npcs[i].actionTimer = 4; // delete time
resetPlayersInCombat(i);
if (!crypt && !barrows && c != null) {
c.incrementNpcKillCount(npcs[i].npcType, 1);
if (c.displayRegularKcMessages || (c.displayBossKcMessages && Constants.BOSS_NPC_IDS.contains(npcs[i].npcType)) || (c.displaySlayerKcMessages && Constants.SLAYER_NPC_IDS.contains(npcs[i].npcType))) {
c.getPacketSender().sendMessage("Your " + npcs[i].name() + " kill count is now: " + c.getNpcKillCount(npcs[i].npcType));
}
}
} else if (npcs[i].actionTimer == 0
&& npcs[i].applyDead
&& npcs[i].needRespawn == false) {
Expand Down
18 changes: 18 additions & 0 deletions 2006Scape Server/src/main/java/com/rs2/game/players/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,24 @@ public abstract class Player {
private GateHandler gateHandler = new GateHandler();
private SingleGates singleGates = new SingleGates();
private DoubleGates doubleGates = new DoubleGates();

private Map<Integer, Integer> npcKillCounts = new HashMap<>();
public boolean displayBossKcMessages = true;
ipkpjersi marked this conversation as resolved.
Show resolved Hide resolved
public boolean displaySlayerKcMessages = false;
public boolean displayRegularKcMessages = false;

public int getNpcKillCount(int npcId) {
return npcKillCounts.getOrDefault(npcId, 0);
}

public Map<Integer, Integer> getNpcKillCounts() {
return npcKillCounts;
}

public void incrementNpcKillCount(int npcId, int count) {
npcKillCounts.put(npcId, npcKillCounts.getOrDefault(npcId, 0) + count);
}

public int lastMainFrameInterface = -1; //Possibly used in future to prevent packet exploits

public int getXPRate() { return xpRate; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.Map;

import com.rs2.util.Misc;

Expand Down Expand Up @@ -436,6 +437,15 @@ public static int loadPlayerInfo(Client player, String playerName, String player
case "discord-user-id":
player.discordCode = token2;
break;
case "display-boss-kc-messages":
player.displayBossKcMessages = Boolean.parseBoolean(token2);
break;
case "display-slayer-kc-messages":
player.displaySlayerKcMessages = Boolean.parseBoolean(token2);
break;
case "display-regular-kc-messages":
player.displayRegularKcMessages = Boolean.parseBoolean(token2);
break;
}
break;
case 3:
Expand Down Expand Up @@ -477,6 +487,16 @@ public static int loadPlayerInfo(Client player, String playerName, String player
if (token.equals("character-ignore")) {
player.ignores[Integer.parseInt(token3[0])] = Long.parseLong(token3[1]);
}
case 10:
if (token.startsWith("npcid-")) {
try {
int npcId = Integer.parseInt(token.substring(6));
int killCount = Integer.parseInt(token2);
player.incrementNpcKillCount(npcId, killCount);
} catch (NumberFormatException e) {
System.out.println("Error parsing NPC kill count for " + token);
}
}
break;
}
} else {
Expand Down Expand Up @@ -508,6 +528,9 @@ public static int loadPlayerInfo(Client player, String playerName, String player
case "[IGNORES]":
ReadMode = 9;
break;
case "[NPC-KILLS]":
ReadMode = 10;
break;
case "[EOF]":
try {
characterfile.close();
Expand Down Expand Up @@ -828,6 +851,12 @@ public static boolean saveGame(Player player) {
characterfile.newLine();
characterfile.write("discord-user-id = " + player.discordCode);
characterfile.newLine();
characterfile.write("display-boss-kc-messages = " + player.displayBossKcMessages);
characterfile.newLine();
characterfile.write("display-slayer-kc-messages = " + player.displaySlayerKcMessages);
characterfile.newLine();
characterfile.write("display-regular-kc-messages = " + player.displayRegularKcMessages);
characterfile.newLine();
characterfile.newLine();

/* EQUIPMENT */
Expand Down Expand Up @@ -900,6 +929,14 @@ public static boolean saveGame(Player player) {
}
characterfile.newLine();

characterfile.write("[NPC-KILLS]");
characterfile.newLine();
for (Map.Entry<Integer, Integer> entry : player.getNpcKillCounts().entrySet()) {
characterfile.write("npcid-" + entry.getKey() + " = " + entry.getValue());
characterfile.newLine();
}
characterfile.newLine();

/* EOF */
characterfile.write("[EOF]");
characterfile.newLine();
Expand Down
Loading