diff --git a/config.yaml b/config.yaml index e3a5fc5f2f..73710b8b87 100644 --- a/config.yaml +++ b/config.yaml @@ -461,3 +461,7 @@ server: #Event End Timestamp EVENT_END_TIMESTAMP: 1428897600000 + #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 diff --git a/src/main/java/config/ServerConfig.java b/src/main/java/config/ServerConfig.java index 5aee568e01..7d5372d373 100644 --- a/src/main/java/config/ServerConfig.java +++ b/src/main/java/config/ServerConfig.java @@ -1,5 +1,9 @@ package config; +import tools.Pair; + +import java.util.*; + public class ServerConfig { //Thread Tracker Configuration public boolean USE_THREAD_TRACKER; @@ -163,7 +167,7 @@ public class ServerConfig { public long NAME_CHANGE_COOLDOWN; public long WORLD_TRANSFER_COOLDOWN=NAME_CHANGE_COOLDOWN;//Cooldown for world tranfers, default is same as name change (30 days). public boolean INSTANT_NAME_CHANGE; - public long REBIRTH_NPC_ID; + public int REBIRTH_NPC_ID; //Dangling Items/Locks Configuration public int ITEM_EXPIRE_TIME ; @@ -305,4 +309,6 @@ public class ServerConfig { //Event End Timestamp public long EVENT_END_TIMESTAMP; + //Custom NPC overrides. NPC ID to Name pair. + public List NPCS_SCRIPTABLE = new ArrayList<>(); } diff --git a/src/main/java/constants/game/ScriptableNPCConstants.java b/src/main/java/constants/game/ScriptableNPCConstants.java deleted file mode 100644 index df8a255cf9..0000000000 --- a/src/main/java/constants/game/ScriptableNPCConstants.java +++ /dev/null @@ -1,24 +0,0 @@ -package constants.game; - -/** - * @brief ScriptableNPCConstants - * @author GabrielSin - * @date 16/09/2018 - * - * Adaptations to use Pair and Set, in order to suit a one-packet marshall. - * Adapted by Ronan - */ - -import java.util.HashSet; -import java.util.Set; -import tools.Pair; - -public class ScriptableNPCConstants { - - public static final Set> SCRIPTABLE_NPCS = new HashSet>(){{ - //add(new Pair<>(9200000, "Cody")); - add(new Pair<>(9001105, "Grandpa Moon Bunny")); - }}; - -} - \ No newline at end of file diff --git a/src/main/java/net/server/channel/handlers/PlayerLoggedinHandler.java b/src/main/java/net/server/channel/handlers/PlayerLoggedinHandler.java index 4db6a00253..d0d18c88e7 100644 --- a/src/main/java/net/server/channel/handlers/PlayerLoggedinHandler.java +++ b/src/main/java/net/server/channel/handlers/PlayerLoggedinHandler.java @@ -26,7 +26,6 @@ import client.inventory.*; import client.keybind.MapleKeyBinding; import config.YamlConfig; import constants.game.GameConstants; -import constants.game.ScriptableNPCConstants; import net.AbstractMaplePacketHandler; import net.server.PlayerBuffValueHolder; import net.server.Server; @@ -409,7 +408,14 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler { } if (YamlConfig.config.server.USE_NPCS_SCRIPTABLE) { - c.announce(MaplePacketCreator.setNPCScriptable(ScriptableNPCConstants.SCRIPTABLE_NPCS)); + List npcsIds = YamlConfig.config.server.NPCS_SCRIPTABLE; + + // 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); + } + + c.announce(MaplePacketCreator.setNPCScriptable(YamlConfig.config.server.NPCS_SCRIPTABLE)); } if(newcomer) player.setLoginTime(System.currentTimeMillis()); diff --git a/src/main/java/tools/MaplePacketCreator.java b/src/main/java/tools/MaplePacketCreator.java index 453561979c..1bb4ccf090 100644 --- a/src/main/java/tools/MaplePacketCreator.java +++ b/src/main/java/tools/MaplePacketCreator.java @@ -8318,17 +8318,24 @@ public class MaplePacketCreator { mplew.writeInt(transition); return mplew.getPacket(); } - - public static byte[] setNPCScriptable(Set> scriptNpcDescriptions) { // thanks to GabrielSin + + /** + * Makes the NPCs provided set as scriptable, informing the client to search for js scripts for these NPCs even + * if they already have entries within the wz files. + * + * @param scriptableNpcIds Ids of npcs to enable scripts for. + * @return a packet which makes the npc's provided scriptable. + */ + public static byte[] setNPCScriptable(List scriptableNpcIds) { // thanks to GabrielSin MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter(); mplew.writeShort(SendOpcode.SET_NPC_SCRIPTABLE.getValue()); - mplew.write(scriptNpcDescriptions.size()); - for (Pair p : scriptNpcDescriptions) { - mplew.writeInt(p.getLeft()); - mplew.writeMapleAsciiString(p.getRight()); + mplew.write(scriptableNpcIds.size()); + scriptableNpcIds.forEach(id -> { + mplew.writeInt(id); + mplew.writeMapleAsciiString("NPC " + id); // The client needs a name for the npc, but it doesn't seem to do anything. mplew.writeInt(0); // start time mplew.writeInt(Integer.MAX_VALUE); // end time - } + }); return mplew.getPacket(); } @@ -8374,17 +8381,17 @@ public class MaplePacketCreator { final MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter(); mplew.writeShort(SendOpcode.TOURNAMENT_SET_PRIZE.getValue()); - //0 = "You have failed the set the prize. Please check the item number again." - //1 = "You have successfully set the prize." - mplew.write(bSetPrize); - - mplew.write(bHasPrize); - - if(bHasPrize != 0) - { - mplew.writeInt(nItemID1); - mplew.writeInt(nItemID2); - } + //0 = "You have failed the set the prize. Please check the item number again." + //1 = "You have successfully set the prize." + mplew.write(bSetPrize); + + mplew.write(bHasPrize); + + if(bHasPrize != 0) + { + mplew.writeInt(nItemID1); + mplew.writeInt(nItemID2); + } return mplew.getPacket(); } @@ -8393,11 +8400,11 @@ public class MaplePacketCreator { final MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter(); mplew.writeShort(SendOpcode.TOURNAMENT_UEW.getValue()); - //Is this a bitflag o.o ? - //2 = "You have reached the finals by default." - //4 = "You have reached the semifinals by default." - //8 or 16 = "You have reached the round of %n by default." | Encodes nState as %n ?! - mplew.write(nState); + //Is this a bitflag o.o ? + //2 = "You have reached the finals by default." + //4 = "You have reached the semifinals by default." + //8 or 16 = "You have reached the round of %n by default." | Encodes nState as %n ?! + mplew.write(nState); return mplew.getPacket(); }