Added the ability to specify a custom rebirth npc id, which is automatically added to the list of scriptable npcs for overriding. Changed scriptable npcs to use config instead of a constants file, so that users can easily modify them without digging into the code and requiring a rebuild.

This commit is contained in:
James McDowell
2021-05-16 14:46:38 +10:00
parent 45ca7009c8
commit cff3d3df56
5 changed files with 49 additions and 50 deletions

View File

@@ -461,3 +461,7 @@ server:
#Event End Timestamp #Event End Timestamp
EVENT_END_TIMESTAMP: 1428897600000 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

View File

@@ -1,5 +1,9 @@
package config; package config;
import tools.Pair;
import java.util.*;
public class ServerConfig { public class ServerConfig {
//Thread Tracker Configuration //Thread Tracker Configuration
public boolean USE_THREAD_TRACKER; public boolean USE_THREAD_TRACKER;
@@ -163,7 +167,7 @@ public class ServerConfig {
public long NAME_CHANGE_COOLDOWN; 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 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 boolean INSTANT_NAME_CHANGE;
public long REBIRTH_NPC_ID; public int REBIRTH_NPC_ID;
//Dangling Items/Locks Configuration //Dangling Items/Locks Configuration
public int ITEM_EXPIRE_TIME ; public int ITEM_EXPIRE_TIME ;
@@ -305,4 +309,6 @@ public class ServerConfig {
//Event End Timestamp //Event End Timestamp
public long EVENT_END_TIMESTAMP; public long EVENT_END_TIMESTAMP;
//Custom NPC overrides. NPC ID to Name pair.
public List<Integer> NPCS_SCRIPTABLE = new ArrayList<>();
} }

View File

@@ -1,24 +0,0 @@
package constants.game;
/**
* @brief ScriptableNPCConstants
* @author GabrielSin <gabrielsin@playellin.net>
* @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<Pair<Integer, String>> SCRIPTABLE_NPCS = new HashSet<Pair<Integer, String>>(){{
//add(new Pair<>(9200000, "Cody"));
add(new Pair<>(9001105, "Grandpa Moon Bunny"));
}};
}

View File

@@ -26,7 +26,6 @@ import client.inventory.*;
import client.keybind.MapleKeyBinding; import client.keybind.MapleKeyBinding;
import config.YamlConfig; import config.YamlConfig;
import constants.game.GameConstants; import constants.game.GameConstants;
import constants.game.ScriptableNPCConstants;
import net.AbstractMaplePacketHandler; import net.AbstractMaplePacketHandler;
import net.server.PlayerBuffValueHolder; import net.server.PlayerBuffValueHolder;
import net.server.Server; import net.server.Server;
@@ -409,7 +408,14 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
} }
if (YamlConfig.config.server.USE_NPCS_SCRIPTABLE) { if (YamlConfig.config.server.USE_NPCS_SCRIPTABLE) {
c.announce(MaplePacketCreator.setNPCScriptable(ScriptableNPCConstants.SCRIPTABLE_NPCS)); List<Integer> 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()); if(newcomer) player.setLoginTime(System.currentTimeMillis());

View File

@@ -8319,16 +8319,23 @@ public class MaplePacketCreator {
return mplew.getPacket(); return mplew.getPacket();
} }
public static byte[] setNPCScriptable(Set<Pair<Integer, String>> 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<Integer> scriptableNpcIds) { // thanks to GabrielSin
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter(); MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
mplew.writeShort(SendOpcode.SET_NPC_SCRIPTABLE.getValue()); mplew.writeShort(SendOpcode.SET_NPC_SCRIPTABLE.getValue());
mplew.write(scriptNpcDescriptions.size()); mplew.write(scriptableNpcIds.size());
for (Pair<Integer, String> p : scriptNpcDescriptions) { scriptableNpcIds.forEach(id -> {
mplew.writeInt(p.getLeft()); mplew.writeInt(id);
mplew.writeMapleAsciiString(p.getRight()); 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(0); // start time
mplew.writeInt(Integer.MAX_VALUE); // end time mplew.writeInt(Integer.MAX_VALUE); // end time
} });
return mplew.getPacket(); return mplew.getPacket();
} }