From e967294eb9a1dd4beb58228b7521ddf231d01a53 Mon Sep 17 00:00:00 2001 From: James McDowell Date: Wed, 26 May 2021 19:41:27 +1000 Subject: [PATCH] Add back in NPC conversation names The names of the npc conversations were useful for context. Added them back in. --- config.yaml | 4 ++-- src/main/java/config/ServerConfig.java | 2 +- .../channel/handlers/PlayerLoggedinHandler.java | 14 ++++++++++---- src/main/java/tools/MaplePacketCreator.java | 7 ++++--- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/config.yaml b/config.yaml index 73710b8b87..54d43f32bf 100644 --- a/config.yaml +++ b/config.yaml @@ -463,5 +463,5 @@ server: #Any NPC ids that should search for a js override script (useful if they already have wz entries since otherwise they're ignored). NPCS_SCRIPTABLE: - #- 9200000 # Cody - - 9001105 # Grandpa moon bunny + #9200000: Talk to Cody # Cody + 9001105: Rescue Gaga! # Grandpa moon bunny diff --git a/src/main/java/config/ServerConfig.java b/src/main/java/config/ServerConfig.java index 7095bce226..34beaea4df 100644 --- a/src/main/java/config/ServerConfig.java +++ b/src/main/java/config/ServerConfig.java @@ -308,5 +308,5 @@ public class ServerConfig { public long EVENT_END_TIMESTAMP; //Custom NPC overrides. List of NPC IDs. - public List NPCS_SCRIPTABLE = new ArrayList<>(); + public Map NPCS_SCRIPTABLE = new HashMap<>(); } diff --git a/src/main/java/net/server/channel/handlers/PlayerLoggedinHandler.java b/src/main/java/net/server/channel/handlers/PlayerLoggedinHandler.java index f5ec11e317..75c2d12958 100644 --- a/src/main/java/net/server/channel/handlers/PlayerLoggedinHandler.java +++ b/src/main/java/net/server/channel/handlers/PlayerLoggedinHandler.java @@ -54,6 +54,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.*; import java.util.Map.Entry; +import java.util.stream.Collectors; public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler { @@ -406,15 +407,20 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler { eim.registerPlayer(player); } } - + + // Tell the client to use the custom scripts available for the NPCs provided, instead of the WZ entries. if (YamlConfig.config.server.USE_NPCS_SCRIPTABLE) { - // Create a set to remove duplicate entries if they exist. - Set npcsIds = new HashSet<>(YamlConfig.config.server.NPCS_SCRIPTABLE); + // Create a copy to prevent always adding entries to the server's list. + Map npcsIds = YamlConfig.config.server.NPCS_SCRIPTABLE + .entrySet().stream().collect(Collectors.toMap( + entry -> Integer.parseInt(entry.getKey()), + Entry::getValue + )); // Any npc be specified as the rebirth npc. Allow the npc to use custom scripts explicitly. if (YamlConfig.config.server.USE_REBIRTH_SYSTEM) { - npcsIds.add(YamlConfig.config.server.REBIRTH_NPC_ID); + npcsIds.put(YamlConfig.config.server.REBIRTH_NPC_ID, "Rebirth"); } c.announce(MaplePacketCreator.setNPCScriptable(npcsIds)); diff --git a/src/main/java/tools/MaplePacketCreator.java b/src/main/java/tools/MaplePacketCreator.java index d7f259eda7..50ee148ad7 100644 --- a/src/main/java/tools/MaplePacketCreator.java +++ b/src/main/java/tools/MaplePacketCreator.java @@ -8326,13 +8326,14 @@ public class MaplePacketCreator { * @param scriptableNpcIds Ids of npcs to enable scripts for. * @return a packet which makes the npc's provided scriptable. */ - public static byte[] setNPCScriptable(Set scriptableNpcIds) { // thanks to GabrielSin + public static byte[] setNPCScriptable(Map scriptableNpcIds) { // thanks to GabrielSin MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter(); mplew.writeShort(SendOpcode.SET_NPC_SCRIPTABLE.getValue()); mplew.write(scriptableNpcIds.size()); - scriptableNpcIds.forEach(id -> { + scriptableNpcIds.forEach((id, name) -> { mplew.writeInt(id); - mplew.writeMapleAsciiString("NPC " + id); // The client needs a name for the npc, but it doesn't seem to do anything. + // The client needs a name for the npc conversation, which is displayed under etc when the npc has a quest available. + mplew.writeMapleAsciiString(name); mplew.writeInt(0); // start time mplew.writeInt(Integer.MAX_VALUE); // end time });