Merge remote-tracking branch 'upstream/master' into Custom-rebirth-npc

This commit is contained in:
James McDowell
2021-05-26 19:44:58 +10:00
318 changed files with 1872 additions and 1719 deletions

View File

@@ -24,7 +24,6 @@ package client;
import client.inventory.MapleInventoryType;
import config.YamlConfig;
import constants.game.GameConstants;
import jdk.nashorn.api.scripting.NashornScriptEngine;
import net.server.Server;
import net.server.audit.locks.MonitoredLockType;
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
@@ -50,6 +49,7 @@ import server.maps.MapleMap;
import server.maps.MapleMiniDungeonInfo;
import tools.*;
import javax.script.ScriptEngine;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
@@ -85,7 +85,7 @@ public class MapleClient {
private long lastPong;
private int gmlevel;
private Set<String> macs = new HashSet<>();
private Map<String, NashornScriptEngine> engines = new HashMap<>();
private Map<String, ScriptEngine> engines = new HashMap<>();
private byte characterSlots = 3;
private byte loginattempt = 0;
private String pin = "";
@@ -1041,11 +1041,11 @@ public class MapleClient {
gmlevel = level;
}
public void setScriptEngine(String name, NashornScriptEngine e) {
engines.put(name, e);
public void setScriptEngine(String name, ScriptEngine e) {
engines.put(name, e);
}
public NashornScriptEngine getScriptEngine(String name) {
public ScriptEngine getScriptEngine(String name) {
return engines.get(name);
}

View File

@@ -5,32 +5,6 @@ public class ServerConstants {
//Server Version
public static short VERSION = 83;
//Java Configuration
public static final boolean JAVA_8 = getJavaVersion() >= 8; //Max amount of times a party leader is allowed to persist on the Party Search before entry expiration (thus needing to manually restart the Party Search to be able to search for members).
//Debug Variables
public static int[] DEBUG_VALUES = new int[10]; // Field designed for packet testing purposes
// https://github.com/openstreetmap/josm/blob/a3a6e8a6b657cf4c5b4c64ea14d6e87be6280d65/src/org/openstreetmap/josm/tools/Utils.java#L1566-L1585
// Added by kolakcc (Familiar)
/**
* Returns the Java version as an int value.
* @return the Java version as an int value (8, 9, etc.)
* @since 12130
*/
public static int getJavaVersion() {
String version = System.getProperty("java.version");
if (version.startsWith("1.")) {
version = version.substring(2);
}
// Allow these formats:
// 1.8.0_72-ea
// 9-ea
// 9
// 9.0.1
int dotPos = version.indexOf('.');
int dashPos = version.indexOf('-');
return Integer.parseInt(version.substring(0,
dotPos > -1 ? dotPos : dashPos > -1 ? dashPos : 1));
}
}

View File

@@ -28,7 +28,6 @@ import client.inventory.manipulator.MapleInventoryManipulator;
import config.YamlConfig;
import constants.game.GameConstants;
import constants.inventory.ItemConstants;
import constants.net.ServerConstants;
import net.server.Server;
import net.server.guild.MapleGuild;
import net.server.world.MapleParty;
@@ -217,45 +216,30 @@ public class AbstractPlayerInteraction {
public boolean canHold(int itemid, int quantity, int removeItemid, int removeQuantity) {
return canHoldAllAfterRemoving(Collections.singletonList(itemid), Collections.singletonList(quantity), Collections.singletonList(removeItemid), Collections.singletonList(removeQuantity));
}
private List<Integer> convertToIntegerArray(List<Object> list) {
List<Integer> intList = new ArrayList<>(); // JAVA 7 Rhino script engine. Thanks Bruno, felipepm10 for noticing a typecast issue here.
if (ServerConstants.JAVA_8) {
for (Object d: list) {
intList.add((Integer) d);
}
} else {
for (Object d: list) {
intList.add(((Double) d).intValue());
}
}
return intList;
private List<Integer> convertToIntegerList(List<Object> objects) {
List<Integer> intList = new ArrayList<>();
for (Object object : objects) {
intList.add((Integer) object);
}
public boolean canHoldAll(List<Object> itemids) {
List<Object> quantity = new LinkedList<>();
if (ServerConstants.JAVA_8) {
Integer intOne = 1;
for (int i = 0; i < itemids.size(); i++) {
quantity.add(intOne);
}
} else {
Double doubleOne = 1.0;
for (int i = 0; i < itemids.size(); i++) {
quantity.add(doubleOne);
}
}
return canHoldAll(itemids, quantity);
return intList;
}
public boolean canHoldAll(List<Object> itemids) {
List<Object> quantity = new LinkedList<>();
final int intOne = 1;
for (int i = 0; i < itemids.size(); i++) {
quantity.add(intOne);
}
return canHoldAll(itemids, quantity);
}
public boolean canHoldAll(List<Object> itemids, List<Object> quantity) {
return canHoldAll(convertToIntegerArray(itemids), convertToIntegerArray(quantity), true);
return canHoldAll(convertToIntegerList(itemids), convertToIntegerList(quantity), true);
}
private boolean canHoldAll(List<Integer> itemids, List<Integer> quantity, boolean isInteger) {

View File

@@ -22,58 +22,68 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package scripting;
import client.MapleClient;
import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine;
import tools.FilePrinter;
import javax.script.*;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import javax.script.*;
import constants.net.ServerConstants;
import jdk.nashorn.api.scripting.NashornScriptEngine;
import tools.FilePrinter;
/**
*
* @author Matze
*/
public abstract class AbstractScriptManager {
private ScriptEngineFactory sef;
private final ScriptEngineFactory sef;
protected AbstractScriptManager() {
sef = new ScriptEngineManager().getEngineByName("javascript").getFactory();
sef = new ScriptEngineManager().getEngineByName("graal.js").getFactory();
}
protected NashornScriptEngine getScriptEngine(String path) {
protected ScriptEngine getInvocableScriptEngine(String path) {
path = "scripts/" + path;
File scriptFile = new File(path);
if (!scriptFile.exists()) {
return null;
}
NashornScriptEngine engine = (NashornScriptEngine) sef.getScriptEngine();
ScriptEngine engine = sef.getScriptEngine();
if (!(engine instanceof GraalJSScriptEngine graalScriptEngine)) {
throw new IllegalStateException("ScriptEngineFactory did not provide a GraalJSScriptEngine");
}
enableScriptHostAccess(graalScriptEngine);
try (FileReader fr = new FileReader(scriptFile)) {
if (ServerConstants.JAVA_8){
engine.eval("load('nashorn:mozilla_compat.js');" + System.lineSeparator());
}
engine.eval(fr);
} catch (final ScriptException | IOException t) {
FilePrinter.printError(FilePrinter.INVOCABLE + path.substring(12), t, path);
return null;
}
return engine;
return graalScriptEngine;
}
protected NashornScriptEngine getScriptEngine(String path, MapleClient c) {
NashornScriptEngine engine = c.getScriptEngine("scripts/" + path);
protected ScriptEngine getInvocableScriptEngine(String path, MapleClient c) {
ScriptEngine engine = c.getScriptEngine("scripts/" + path);
if (engine == null) {
engine = getScriptEngine(path);
engine = getInvocableScriptEngine(path);
c.setScriptEngine(path, engine);
}
return engine;
}
/**
* Allow usage of "Java.type()" in script to look up host class
*/
private void enableScriptHostAccess(GraalJSScriptEngine engine) {
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
bindings.put("polyglot.js.allowHostAccess", true);
bindings.put("polyglot.js.allowHostClassLookup", true);
}
protected void resetContext(String path, MapleClient c) {
c.removeScriptEngine("scripts/" + path);
}

View File

@@ -0,0 +1,44 @@
package scripting;
import net.jcip.annotations.ThreadSafe;
import javax.script.Invocable;
import javax.script.ScriptException;
/**
* Thread safe wrapper around Invocable.
* Thread safety is achieved by synchronizing all methods.
* Needed to get around the restriction that GraalVM imposes on evaluated scripts: no concurrent access allowed.
*/
@ThreadSafe
public class SynchronizedInvocable implements Invocable {
private final Invocable invocable;
private SynchronizedInvocable(Invocable invocable) {
this.invocable = invocable;
}
public static Invocable of(Invocable invocable) {
return new SynchronizedInvocable(invocable);
}
@Override
public synchronized Object invokeMethod(Object thiz, String name, Object... args) throws ScriptException, NoSuchMethodException {
return invocable.invokeMethod(thiz, name, args);
}
@Override
public synchronized Object invokeFunction(String name, Object... args) throws ScriptException, NoSuchMethodException {
return invocable.invokeFunction(name, args);
}
@Override
public synchronized <T> T getInterface(Class<T> clasz) {
return invocable.getInterface(clasz);
}
@Override
public synchronized <T> T getInterface(Object thiz, Class<T> clasz) {
return invocable.getInterface(thiz, clasz);
}
}

View File

@@ -26,7 +26,6 @@ import client.Skill;
import client.SkillFactory;
import config.YamlConfig;
import constants.inventory.ItemConstants;
import constants.net.ServerConstants;
import net.server.audit.LockCollector;
import net.server.audit.locks.*;
import net.server.audit.locks.factory.MonitoredReadLockFactory;
@@ -214,7 +213,7 @@ public class EventInstanceManager {
}
}
public Object invokeScriptFunction(String name, Object... args) throws ScriptException, NoSuchMethodException {
if (!disposed) {
return em.getIv().invokeFunction(name, args);
@@ -557,31 +556,25 @@ public class EventInstanceManager {
}
public void monsterKilled(MapleCharacter chr, final MapleMonster mob) {
try {
int inc;
if (ServerConstants.JAVA_8) {
inc = (int)invokeScriptFunction("monsterValue", EventInstanceManager.this, mob.getId());
} else {
inc = ((Double) invokeScriptFunction("monsterValue", EventInstanceManager.this, mob.getId())).intValue();
}
if (inc != 0) {
Integer kc = killCount.get(chr);
if (kc == null) {
kc = inc;
} else {
kc += inc;
}
killCount.put(chr, kc);
if (expedition != null){
expedition.monsterKilled(chr, mob);
}
}
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
try {
final int inc = (int) invokeScriptFunction("monsterValue", EventInstanceManager.this, mob.getId());
if (inc != 0) {
Integer kc = killCount.get(chr);
if (kc == null) {
kc = inc;
} else {
kc += inc;
}
killCount.put(chr, kc);
if (expedition != null) {
expedition.monsterKilled(chr, mob);
}
}
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
public int getKillCount(MapleCharacter chr) {
Integer kc = killCount.get(chr);
@@ -886,31 +879,25 @@ public class EventInstanceManager {
public MapleMonster getMonster(int mid) {
return(MapleLifeFactory.getMonster(mid));
}
private List<Integer> convertToIntegerArray(List<Object> list) {
List<Integer> intList = new ArrayList<>();
if (ServerConstants.JAVA_8) {
for (Object d: list) {
intList.add((Integer) d);
private List<Integer> convertToIntegerList(List<Object> objects) {
List<Integer> intList = new ArrayList<>();
for (Object object : objects) {
intList.add((Integer) object);
}
} else {
for (Object d: list) {
intList.add(((Double) d).intValue());
}
}
return intList;
return intList;
}
public void setEventClearStageExp(List<Object> gain) {
onMapClearExp.clear();
onMapClearExp.addAll(convertToIntegerArray(gain));
onMapClearExp.addAll(convertToIntegerList(gain));
}
public void setEventClearStageMeso(List<Object> gain) {
onMapClearMeso.clear();
onMapClearMeso.addAll(convertToIntegerArray(gain));
onMapClearMeso.addAll(convertToIntegerList(gain));
}
public Integer getClearStageExp(int stage) { //stage counts from ONE.
@@ -940,7 +927,7 @@ public class EventInstanceManager {
}
public final void setExclusiveItems(List<Object> items) {
List<Integer> exclusive = convertToIntegerArray(items);
List<Integer> exclusive = convertToIntegerList(items);
wL.lock();
try {
@@ -968,8 +955,8 @@ public class EventInstanceManager {
if(eventLevel <= 0 || eventLevel > YamlConfig.config.server.MAX_EVENT_LEVELS) return;
eventLevel--; //event level starts from 1
List<Integer> rewardIds = convertToIntegerArray(rwds);
List<Integer> rewardQtys = convertToIntegerArray(qtys);
List<Integer> rewardIds = convertToIntegerList(rwds);
List<Integer> rewardQtys = convertToIntegerList(qtys);
//rewardsSet and rewardsQty hold temporary values
wL.lock();

View File

@@ -24,10 +24,6 @@ package scripting.event;
import client.MapleCharacter;
import config.YamlConfig;
import constants.game.GameConstants;
import constants.net.ServerConstants;
import jdk.nashorn.api.scripting.NashornScriptEngine;
import jdk.nashorn.api.scripting.ScriptObjectMirror;
import jdk.nashorn.api.scripting.ScriptUtils;
import net.server.Server;
import net.server.audit.LockCollector;
import net.server.audit.locks.MonitoredLockType;
@@ -48,6 +44,7 @@ import server.maps.MapleMap;
import server.quest.MapleQuest;
import tools.exceptions.EventInstanceInProgressException;
import javax.script.Invocable;
import javax.script.ScriptException;
import java.util.*;
import java.util.concurrent.Semaphore;
@@ -62,7 +59,7 @@ import java.util.logging.Logger;
* @author Ronan
*/
public class EventManager {
private NashornScriptEngine iv;
private Invocable iv;
private Channel cserv;
private World wserv;
private Server server;
@@ -85,7 +82,7 @@ public class EventManager {
private static final int maxLobbys = 8; // an event manager holds up to this amount of concurrent lobbys
public EventManager(Channel cserv, NashornScriptEngine iv, String name) {
public EventManager(Channel cserv, Invocable iv, String name) {
this.server = Server.getInstance();
this.iv = iv;
this.cserv = cserv;
@@ -151,20 +148,14 @@ public class EventManager {
queueLock = queueLock.dispose();
startLock = startLock.dispose();
}
private List<Integer> convertToIntegerArray(List<Object> list) {
private List<Integer> convertToIntegerList(List<Object> objects) {
List<Integer> intList = new ArrayList<>();
if (ServerConstants.JAVA_8) {
for (Object d: list) {
intList.add((Integer) d);
}
} else {
for (Object d: list) {
intList.add(((Double) d).intValue());
}
for (Object object : objects) {
intList.add((Integer) object);
}
return intList;
}
@@ -172,26 +163,11 @@ public class EventManager {
return YamlConfig.config.server.EVENT_LOBBY_DELAY;
}
private List<Integer> getLobbyRange() {
private int getMaxLobbies() {
try {
if (!ServerConstants.JAVA_8) {
return convertToIntegerArray((List<Object>)iv.invokeFunction("setLobbyRange", (Object) null));
} else { // java 8 support here thanks to MedicOP
ScriptObjectMirror object = (ScriptObjectMirror) iv.invokeFunction("setLobbyRange", (Object) null);
int[] to = object.to(int[].class);
List<Integer> list = new ArrayList<>();
for (int i : to) {
list.add(i);
}
return list;
}
return (int) iv.invokeFunction("getMaxLobbies");
} catch (ScriptException | NoSuchMethodException ex) { // they didn't define a lobby range
List<Integer> defaultRange = new ArrayList<>();
defaultRange.add(0);
defaultRange.add(maxLobbys);
return defaultRange;
return maxLobbys;
}
}
@@ -235,7 +211,7 @@ public class EventManager {
return cserv;
}
public NashornScriptEngine getIv() {
public Invocable getIv() {
return iv;
}
@@ -351,23 +327,19 @@ public class EventManager {
public String getName() {
return name;
}
private int availableLobbyInstance() {
List<Integer> lr = getLobbyRange();
int lb = 0, hb = 0;
if(lr.size() >= 2) {
lb = Math.max(lr.get(0), 0);
hb = Math.min(lr.get(1), maxLobbys - 1);
int maxLobbies = getMaxLobbies();
if (maxLobbies > 0) {
for (int i = 0; i < maxLobbies; i++) {
if (startLobbyInstance(i)) {
return i;
}
}
for(int i = lb; i <= hb; i++) {
if(startLobbyInstance(i)) {
return i;
}
}
return -1;
}
return -1;
}
private String getInternalScriptExceptionMessage(Throwable a) {
@@ -707,7 +679,7 @@ public class EventManager {
}
registerEventInstance(eim.getName(), lobbyId);
eim.setLeader(leader);
iv.invokeFunction("setup", eim);
eim.setProperty("leader", ldr);
@@ -732,28 +704,21 @@ public class EventManager {
public List<MaplePartyCharacter> getEligibleParty(MapleParty party) {
if (party == null) {
return(new ArrayList<>());
return new ArrayList<>();
}
try {
Object p = iv.invokeFunction("getEligibleParty", party.getPartyMembersOnline());
Object o = iv.invokeFunction("getEligibleParty", party.getPartyMembersOnline());
if(p != null) {
List<MaplePartyCharacter> lmpc;
if(ServerConstants.JAVA_8) {
lmpc = new ArrayList<>(((Map<String, MaplePartyCharacter>)(ScriptUtils.convert(p, Map.class))).values());
} else {
lmpc = new ArrayList<>((List<MaplePartyCharacter>) p);
}
party.setEligibleMembers(lmpc);
return lmpc;
if (o instanceof MaplePartyCharacter[] partyChrs) {
final List<MaplePartyCharacter> eligibleParty = new ArrayList<>(Arrays.asList(partyChrs));
party.setEligibleMembers(eligibleParty);
return eligibleParty;
}
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
return(new ArrayList<>());
return new ArrayList<>();
}
public void clearPQ(EventInstanceManager eim) {

View File

@@ -21,45 +21,44 @@
*/
package scripting.event;
import java.util.concurrent.ConcurrentHashMap;
import net.server.channel.Channel;
import scripting.AbstractScriptManager;
import scripting.SynchronizedInvocable;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import jdk.nashorn.api.scripting.NashornScriptEngine;
import net.server.channel.Channel;
import scripting.AbstractScriptManager;
/**
*
* @author Matze
*/
public class EventScriptManager extends AbstractScriptManager {
private static final String INJECTED_VARIABLE_NAME = "em";
private static EventEntry fallback;
private final Map<String, EventEntry> events = new ConcurrentHashMap<>();
private boolean active = false;
private class EventEntry {
private static class EventEntry {
public EventEntry(NashornScriptEngine iv, EventManager em) {
public EventEntry(Invocable iv, EventManager em) {
this.iv = iv;
this.em = em;
}
public NashornScriptEngine iv;
public Invocable iv;
public EventManager em;
}
private static EventEntry fallback;
private Map<String, EventEntry> events = new ConcurrentHashMap<>();
private boolean active = false;
public EventScriptManager(Channel cserv, String[] scripts) {
super();
public EventScriptManager(final Channel channel, String[] scripts) {
for (String script : scripts) {
if (!script.equals("")) {
NashornScriptEngine iv = getScriptEngine("event/" + script + ".js");
events.put(script, new EventEntry(iv, new EventManager(cserv, iv, script)));
if (!script.isEmpty()) {
events.put(script, initializeEventEntry(script, channel));
}
}
@@ -82,7 +81,6 @@ public class EventScriptManager extends AbstractScriptManager {
public final void init() {
for (EventEntry entry : events.values()) {
try {
entry.iv.put("em", entry.em);
entry.iv.invokeFunction("init", (Object) null);
} catch (Exception ex) {
Logger.getLogger(EventScriptManager.class.getName()).log(Level.SEVERE, null, ex);
@@ -99,14 +97,22 @@ public class EventScriptManager extends AbstractScriptManager {
return;
}
Channel cserv = eventEntries.iterator().next().getValue().em.getChannelServer();
Channel channel = eventEntries.iterator().next().getValue().em.getChannelServer();
for (Entry<String, EventEntry> entry : eventEntries) {
String script = entry.getKey();
NashornScriptEngine iv = getScriptEngine("event/" + script + ".js");
events.put(script, new EventEntry(iv, new EventManager(cserv, iv, script)));
events.put(script, initializeEventEntry(script, channel));
}
}
private EventEntry initializeEventEntry(String script, Channel channel) {
ScriptEngine engine = getInvocableScriptEngine("event/" + script + ".js");
Invocable iv = SynchronizedInvocable.of((Invocable) engine);
EventManager eventManager = new EventManager(channel, iv, script);
engine.put(INJECTED_VARIABLE_NAME, eventManager);
return new EventEntry(iv, eventManager);
}
// Is never being called
public void reload() {
cancel();
reloadScripts();

View File

@@ -23,31 +23,22 @@ package scripting.map;
import client.MapleCharacter;
import client.MapleClient;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.HashMap;
import java.util.Map;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import jdk.nashorn.api.scripting.NashornScriptEngine;
import scripting.AbstractScriptManager;
import tools.FilePrinter;
public class MapScriptManager extends AbstractScriptManager {
import javax.script.Invocable;
import javax.script.ScriptException;
import java.util.HashMap;
import java.util.Map;
public class MapScriptManager extends AbstractScriptManager {
private static final MapScriptManager instance = new MapScriptManager();
private final Map<String, Invocable> scripts = new HashMap<>();
private static MapScriptManager instance = new MapScriptManager();
public static MapScriptManager getInstance() {
return instance;
}
private Map<String, NashornScriptEngine> scripts = new HashMap<>();
private ScriptEngineFactory sef;
private MapScriptManager() {
ScriptEngineManager sem = new ScriptEngineManager();
sef = sem.getEngineByName("javascript").getFactory();
}
public void reloadScripts() {
scripts.clear();
@@ -64,7 +55,7 @@ public class MapScriptManager extends AbstractScriptManager {
}
}
NashornScriptEngine iv = scripts.get(mapScriptPath);
Invocable iv = scripts.get(mapScriptPath);
if (iv != null) {
try {
iv.invokeFunction("start", new MapScriptMethods(c));
@@ -75,7 +66,7 @@ public class MapScriptManager extends AbstractScriptManager {
}
try {
iv = getScriptEngine("map/" + mapScriptPath + ".js");
iv = (Invocable) getInvocableScriptEngine("map/" + mapScriptPath + ".js");
if (iv == null) {
return false;
}
@@ -83,12 +74,10 @@ public class MapScriptManager extends AbstractScriptManager {
scripts.put(mapScriptPath, iv);
iv.invokeFunction("start", new MapScriptMethods(c));
return true;
} catch (final UndeclaredThrowableException | ScriptException ute) {
FilePrinter.printError(FilePrinter.MAP_SCRIPT + mapScriptPath + ".txt", ute);
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.MAP_SCRIPT + mapScriptPath + ".txt", e);
}
return false;
}
}

View File

@@ -23,44 +23,40 @@ package scripting.npc;
import client.MapleCharacter;
import client.MapleClient;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.script.ScriptException;
import jdk.nashorn.api.scripting.NashornScriptEngine;
import net.server.world.MaplePartyCharacter;
import scripting.AbstractScriptManager;
import server.MapleItemInformationProvider.ScriptedItem;
import tools.FilePrinter;
import tools.MaplePacketCreator;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* @author Matze
*/
public class NPCScriptManager extends AbstractScriptManager {
private static final NPCScriptManager instance = new NPCScriptManager();
private static NPCScriptManager instance = new NPCScriptManager();
private final Map<MapleClient, NPCConversationManager> cms = new HashMap<>();
private final Map<MapleClient, Invocable> scripts = new HashMap<>();
public static NPCScriptManager getInstance() {
return instance;
}
private Map<MapleClient, NPCConversationManager> cms = new HashMap<>();
private Map<MapleClient, NashornScriptEngine> scripts = new HashMap<>();
public boolean isNpcScriptAvailable(MapleClient c, String fileName) {
NashornScriptEngine iv = null;
ScriptEngine engine = null;
if (fileName != null) {
iv = getScriptEngine("npc/" + fileName + ".js", c);
engine = getInvocableScriptEngine("npc/" + fileName + ".js", c);
}
return iv != null;
return engine != null;
}
public boolean start(MapleClient c, int npc, MapleCharacter chr) {
@@ -85,30 +81,29 @@ public class NPCScriptManager extends AbstractScriptManager {
public void start(String filename, MapleClient c, int npc, List<MaplePartyCharacter> chrs) {
try {
NPCConversationManager cm = new NPCConversationManager(c, npc, chrs, true);
final NPCConversationManager cm = new NPCConversationManager(c, npc, chrs, true);
cm.dispose();
if (cms.containsKey(c)) {
return;
}
cms.put(c, cm);
NashornScriptEngine iv = getScriptEngine("npc/" + filename + ".js", c);
ScriptEngine engine = getInvocableScriptEngine("npc/" + filename + ".js", c);
if (iv == null) {
if (engine == null) {
c.getPlayer().dropMessage(1, "NPC " + npc + " is uncoded.");
cm.dispose();
return;
}
iv.put("cm", cm);
scripts.put(c, iv);
engine.put("cm", cm);
Invocable invocable = (Invocable) engine;
scripts.put(c, invocable);
try {
iv.invokeFunction("start", chrs);
invocable.invokeFunction("start", chrs);
} catch (final NoSuchMethodException nsme) {
nsme.printStackTrace();
}
} catch (final UndeclaredThrowableException ute) {
FilePrinter.printError(FilePrinter.NPC + npc + ".txt", ute);
dispose(c);
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.NPC + npc + ".txt", e);
dispose(c);
@@ -117,31 +112,33 @@ public class NPCScriptManager extends AbstractScriptManager {
private boolean start(MapleClient c, int npc, int oid, String fileName, MapleCharacter chr, boolean itemScript, String engineName) {
try {
NPCConversationManager cm = new NPCConversationManager(c, npc, oid, fileName, itemScript);
final NPCConversationManager cm = new NPCConversationManager(c, npc, oid, fileName, itemScript);
if (cms.containsKey(c)) {
dispose(c);
}
if (c.canClickNPC()) {
cms.put(c, cm);
NashornScriptEngine iv = null;
ScriptEngine engine = null;
if (!itemScript) {
if (fileName != null) {
iv = getScriptEngine("npc/" + fileName + ".js", c);
engine = getInvocableScriptEngine("npc/" + fileName + ".js", c);
}
} else {
if (fileName != null) { // thanks MiLin for drafting NPC-based item scripts
iv = getScriptEngine("item/" + fileName + ".js", c);
engine = getInvocableScriptEngine("item/" + fileName + ".js", c);
}
}
if (iv == null) {
iv = getScriptEngine("npc/" + npc + ".js", c);
if (engine == null) {
engine = getInvocableScriptEngine("npc/" + npc + ".js", c);
cm.resetItemScript();
}
if (iv == null) {
if (engine == null) {
dispose(c);
return false;
}
iv.put(engineName, cm);
engine.put(engineName, cm);
Invocable iv = (Invocable) engine;
scripts.put(c, iv);
c.setClickedNPC();
try {
@@ -157,21 +154,16 @@ public class NPCScriptManager extends AbstractScriptManager {
c.announce(MaplePacketCreator.enableActions());
}
return true;
} catch (final UndeclaredThrowableException | ScriptException ute) {
} catch (final Exception ute) {
FilePrinter.printError(FilePrinter.NPC + npc + ".txt", ute);
dispose(c);
return false;
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.NPC + npc + ".txt", e);
dispose(c);
return false;
}
}
public void action(MapleClient c, byte mode, byte type, int selection) {
NashornScriptEngine iv = scripts.get(c);
Invocable iv = scripts.get(c);
if (iv != null) {
try {
c.setClickedNPC();

View File

@@ -34,8 +34,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
public class PortalPlayerInteraction extends AbstractPlayerInteraction {
private MaplePortal portal;
private final MaplePortal portal;
public PortalPlayerInteraction(MapleClient c, MaplePortal portal) {
super(c);

View File

@@ -22,59 +22,56 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package scripting.portal;
import client.MapleClient;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.HashMap;
import java.util.Map;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import jdk.nashorn.api.scripting.NashornScriptEngine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scripting.AbstractScriptManager;
import server.maps.MaplePortal;
import tools.FilePrinter;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
import java.util.HashMap;
import java.util.Map;
public class PortalScriptManager extends AbstractScriptManager {
private static final Logger log = LoggerFactory.getLogger(PortalScriptManager.class);
private static final PortalScriptManager instance = new PortalScriptManager();
private final Map<String, PortalScript> scripts = new HashMap<>();
private static PortalScriptManager instance = new PortalScriptManager();
public static PortalScriptManager getInstance() {
return instance;
}
private Map<String, NashornScriptEngine> scripts = new HashMap<>();
private ScriptEngineFactory sef;
private PortalScriptManager() {
ScriptEngineManager sem = new ScriptEngineManager();
sef = sem.getEngineByName("javascript").getFactory();
}
private NashornScriptEngine getPortalScript(String scriptName) {
private PortalScript getPortalScript(String scriptName) throws ScriptException {
String scriptPath = "portal/" + scriptName + ".js";
NashornScriptEngine iv = scripts.get(scriptPath);
if (iv != null) {
return iv;
PortalScript script = scripts.get(scriptPath);
if (script != null) {
return script;
}
iv = getScriptEngine(scriptPath);
if (iv == null) {
ScriptEngine engine = getInvocableScriptEngine(scriptPath);
if (!(engine instanceof Invocable iv)) {
return null;
}
scripts.put(scriptPath, iv);
return iv;
script = iv.getInterface(PortalScript.class);
if (script == null) {
throw new ScriptException(String.format("Portal script \"%s\" fails to implement the PortalScript interface", scriptName));
}
scripts.put(scriptPath, script);
return script;
}
public boolean executePortalScript(MaplePortal portal, MapleClient c) {
try {
NashornScriptEngine iv = getPortalScript(portal.getScriptName());
if (iv != null) {
boolean couldWarp = (boolean) iv.invokeFunction("enter", new PortalPlayerInteraction(c, portal));
return couldWarp;
PortalScript script = getPortalScript(portal.getScriptName());
if (script != null) {
return script.enter(new PortalPlayerInteraction(c, portal));
}
} catch (UndeclaredThrowableException ute) {
FilePrinter.printError(FilePrinter.PORTAL + portal.getScriptName() + ".txt", ute);
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.PORTAL + portal.getScriptName() + ".txt", e);
} catch (Exception e) {
log.warn("Portal script {}", portal.getScriptName(), e);
}
return false;
}

View File

@@ -21,187 +21,187 @@
*/
package scripting.quest;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.HashMap;
import java.util.Map;
import jdk.nashorn.api.scripting.NashornScriptEngine;
import client.MapleClient;
import client.MapleQuestStatus;
import constants.game.GameConstants;
import scripting.AbstractScriptManager;
import server.quest.MapleQuest;
import tools.FilePrinter;
import constants.game.GameConstants;
import client.MapleClient;
import client.MapleQuestStatus;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.HashMap;
import java.util.Map;
/**
*
* @author RMZero213
*/
public class QuestScriptManager extends AbstractScriptManager {
private static final QuestScriptManager instance = new QuestScriptManager();
private static QuestScriptManager instance = new QuestScriptManager();
private final Map<MapleClient, QuestActionManager> qms = new HashMap<>();
private final Map<MapleClient, Invocable> scripts = new HashMap<>();
public static QuestScriptManager getInstance() {
return instance;
}
private Map<MapleClient, QuestActionManager> qms = new HashMap<>();
private Map<MapleClient, NashornScriptEngine> scripts = new HashMap<>();
private NashornScriptEngine getQuestScriptEngine(MapleClient c, short questid) {
NashornScriptEngine iv = getScriptEngine("quest/" + questid + ".js", c);
if (iv == null && GameConstants.isMedalQuest(questid)) {
iv = getScriptEngine("quest/medalQuest.js", c); // start generic medal quest
}
public static QuestScriptManager getInstance() {
return instance;
}
return iv;
private ScriptEngine getQuestScriptEngine(MapleClient c, short questid) {
ScriptEngine engine = getInvocableScriptEngine("quest/" + questid + ".js", c);
if (engine == null && GameConstants.isMedalQuest(questid)) {
engine = getInvocableScriptEngine("quest/medalQuest.js", c); // start generic medal quest
}
return engine;
}
public void start(MapleClient c, short questid, int npc) {
MapleQuest quest = MapleQuest.getInstance(questid);
try {
QuestActionManager qm = new QuestActionManager(c, questid, npc, true);
if (qms.containsKey(c)) {
return;
}
if(c.canClickNPC()) {
qms.put(c, qm);
if (!quest.hasScriptRequirement(false)) { // lack of scripted quest checks found thanks to Mali, Resinate
qm.dispose();
return;
}
NashornScriptEngine iv = getQuestScriptEngine(c, questid);
if (iv == null) {
FilePrinter.printError(FilePrinter.QUEST_UNCODED, "START Quest " + questid + " is uncoded.");
qm.dispose();
return;
}
iv.put("qm", qm);
scripts.put(c, iv);
c.setClickedNPC();
iv.invokeFunction("start", (byte) 1, (byte) 0, 0);
}
} catch (final UndeclaredThrowableException ute) {
FilePrinter.printError(FilePrinter.QUEST + questid + ".txt", ute);
dispose(c);
} catch (final Throwable t) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", t);
dispose(c);
MapleQuest quest = MapleQuest.getInstance(questid);
try {
QuestActionManager qm = new QuestActionManager(c, questid, npc, true);
if (qms.containsKey(c)) {
return;
}
if (c.canClickNPC()) {
qms.put(c, qm);
if (!quest.hasScriptRequirement(false)) { // lack of scripted quest checks found thanks to Mali, Resinate
qm.dispose();
return;
}
}
ScriptEngine engine = getQuestScriptEngine(c, questid);
if (engine == null) {
FilePrinter.printError(FilePrinter.QUEST_UNCODED, "START Quest " + questid + " is uncoded.");
qm.dispose();
return;
}
engine.put("qm", qm);
Invocable iv = (Invocable) engine;
scripts.put(c, iv);
c.setClickedNPC();
iv.invokeFunction("start", (byte) 1, (byte) 0, 0);
}
} catch (final UndeclaredThrowableException ute) {
FilePrinter.printError(FilePrinter.QUEST + questid + ".txt", ute);
dispose(c);
} catch (final Throwable t) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", t);
dispose(c);
}
}
public void start(MapleClient c, byte mode, byte type, int selection) {
NashornScriptEngine iv = scripts.get(c);
Invocable iv = scripts.get(c);
if (iv != null) {
try {
c.setClickedNPC();
iv.invokeFunction("start", mode, type, selection);
} catch (final UndeclaredThrowableException ute) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", ute);
dispose(c);
} catch (final Throwable t) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", t);
iv.invokeFunction("start", mode, type, selection);
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", e);
dispose(c);
}
}
}
}
public void end(MapleClient c, short questid, int npc) {
MapleQuest quest = MapleQuest.getInstance(questid);
if (!c.getPlayer().getQuest(quest).getStatus().equals(MapleQuestStatus.Status.STARTED) || !c.getPlayer().getMap().containsNPC(npc)) {
dispose(c);
return;
}
try {
QuestActionManager qm = new QuestActionManager(c, questid, npc, false);
if (qms.containsKey(c)) {
return;
}
if(c.canClickNPC()){
qms.put(c, qm);
if (!quest.hasScriptRequirement(true)) {
qm.dispose();
return;
}
NashornScriptEngine iv = getQuestScriptEngine(c, questid);
if (iv == null) {
FilePrinter.printError(FilePrinter.QUEST_UNCODED, "END Quest " + questid + " is uncoded.");
qm.dispose();
return;
}
iv.put("qm", qm);
scripts.put(c, iv);
c.setClickedNPC();
iv.invokeFunction("end", (byte) 1, (byte) 0, 0);
}
} catch (final UndeclaredThrowableException ute) {
FilePrinter.printError(FilePrinter.QUEST + questid + ".txt", ute);
dispose(c);
} catch (final Throwable t) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", t);
dispose(c);
}
}
MapleQuest quest = MapleQuest.getInstance(questid);
if (!c.getPlayer().getQuest(quest).getStatus().equals(MapleQuestStatus.Status.STARTED) || !c.getPlayer().getMap().containsNPC(npc)) {
dispose(c);
return;
}
try {
QuestActionManager qm = new QuestActionManager(c, questid, npc, false);
if (qms.containsKey(c)) {
return;
}
if (c.canClickNPC()) {
qms.put(c, qm);
if (!quest.hasScriptRequirement(true)) {
qm.dispose();
return;
}
ScriptEngine engine = getQuestScriptEngine(c, questid);
if (engine == null) {
FilePrinter.printError(FilePrinter.QUEST_UNCODED, "END Quest " + questid + " is uncoded.");
qm.dispose();
return;
}
engine.put("qm", qm);
Invocable iv = (Invocable) engine;
scripts.put(c, iv);
c.setClickedNPC();
iv.invokeFunction("end", (byte) 1, (byte) 0, 0);
}
} catch (final UndeclaredThrowableException ute) {
FilePrinter.printError(FilePrinter.QUEST + questid + ".txt", ute);
dispose(c);
} catch (final Throwable t) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", t);
dispose(c);
}
}
public void end(MapleClient c, byte mode, byte type, int selection) {
NashornScriptEngine iv = scripts.get(c);
Invocable iv = scripts.get(c);
if (iv != null) {
try {
c.setClickedNPC();
iv.invokeFunction("end", mode, type, selection);
} catch (final UndeclaredThrowableException ute) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", ute);
dispose(c);
} catch (final Throwable t) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", t);
iv.invokeFunction("end", mode, type, selection);
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", e);
dispose(c);
}
}
}
}
public void raiseOpen(MapleClient c, short questid, int npc) {
try {
QuestActionManager qm = new QuestActionManager(c, questid, npc, true);
if (qms.containsKey(c)) {
return;
}
if(c.canClickNPC()) {
qms.put(c, qm);
NashornScriptEngine iv = getQuestScriptEngine(c, questid);
if (iv == null) {
//FilePrinter.printError(FilePrinter.QUEST_UNCODED, "RAISE Quest " + questid + " is uncoded.");
qm.dispose();
return;
}
iv.put("qm", qm);
scripts.put(c, iv);
c.setClickedNPC();
iv.invokeFunction("raiseOpen");
}
} catch (final UndeclaredThrowableException ute) {
FilePrinter.printError(FilePrinter.QUEST + questid + ".txt", ute);
dispose(c);
} catch (final Throwable t) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", t);
dispose(c);
try {
QuestActionManager qm = new QuestActionManager(c, questid, npc, true);
if (qms.containsKey(c)) {
return;
}
}
if (c.canClickNPC()) {
qms.put(c, qm);
public void dispose(QuestActionManager qm, MapleClient c) {
qms.remove(c);
scripts.remove(c);
c.getPlayer().setNpcCooldown(System.currentTimeMillis());
resetContext("quest/" + qm.getQuest() + ".js", c);
c.getPlayer().flushDelayedUpdateQuests();
}
ScriptEngine engine = getQuestScriptEngine(c, questid);
if (engine == null) {
//FilePrinter.printError(FilePrinter.QUEST_UNCODED, "RAISE Quest " + questid + " is uncoded.");
qm.dispose();
return;
}
engine.put("qm", qm);
Invocable iv = (Invocable) engine;
scripts.put(c, iv);
c.setClickedNPC();
iv.invokeFunction("raiseOpen");
}
} catch (final UndeclaredThrowableException ute) {
FilePrinter.printError(FilePrinter.QUEST + questid + ".txt", ute);
dispose(c);
} catch (final Throwable t) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", t);
dispose(c);
}
}
public void dispose(QuestActionManager qm, MapleClient c) {
qms.remove(c);
scripts.remove(c);
c.getPlayer().setNpcCooldown(System.currentTimeMillis());
resetContext("quest/" + qm.getQuest() + ".js", c);
c.getPlayer().flushDelayedUpdateQuests();
}
public void dispose(MapleClient c) {
QuestActionManager qm = qms.get(c);
@@ -210,12 +210,12 @@ public class QuestScriptManager extends AbstractScriptManager {
}
}
public QuestActionManager getQM(MapleClient c) {
return qms.get(c);
}
public void reloadQuestScripts() {
scripts.clear();
qms.clear();
}
public QuestActionManager getQM(MapleClient c) {
return qms.get(c);
}
public void reloadQuestScripts() {
scripts.clear();
qms.clear();
}
}

View File

@@ -28,10 +28,7 @@ import client.inventory.Item;
import client.inventory.MapleInventoryType;
import config.YamlConfig;
import constants.inventory.ItemConstants;
import jdk.nashorn.api.scripting.NashornScriptEngine;
import scripting.AbstractPlayerInteraction;
import scripting.event.EventInstanceManager;
import scripting.event.EventManager;
import server.MapleItemInformationProvider;
import server.TimerManager;
import server.life.MapleLifeFactory;
@@ -44,25 +41,23 @@ import server.partyquest.MapleCarnivalFactory;
import server.partyquest.MapleCarnivalFactory.MCSkill;
import tools.MaplePacketCreator;
import javax.script.ScriptException;
import javax.script.Invocable;
import java.awt.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* @author Lerk
* @author Ronan
*/
public class ReactorActionManager extends AbstractPlayerInteraction {
private MapleReactor reactor;
private NashornScriptEngine iv;
private final MapleReactor reactor;
private final Invocable iv;
private ScheduledFuture<?> sprayTask = null;
public ReactorActionManager(MapleClient c, MapleReactor reactor, NashornScriptEngine iv) {
public ReactorActionManager(MapleClient c, MapleReactor reactor, Invocable iv) {
super(c);
this.reactor = reactor;
this.iv = iv;
@@ -311,29 +306,21 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
public void spawnFakeMonster(int id) {
reactor.getMap().spawnFakeMonsterOnGroundBelow(MapleLifeFactory.getMonster(id), getPosition());
}
public ScheduledFuture<?> schedule(String methodName, long delay) {
return schedule(methodName, null, delay);
/**
* Used for Targa and Scarlion
*/
public void summonBossDelayed(final int mobId, final int delayMs, final int x, final int y, final String bgm,
final String summonMessage) {
TimerManager.getInstance().schedule(() -> {
summonBoss(mobId, x, y, bgm, summonMessage);
}, delayMs);
}
public ScheduledFuture<?> schedule(final String methodName, final EventInstanceManager eim, long delay) {
return TimerManager.getInstance().schedule(() -> {
try {
iv.invokeFunction(methodName, eim);
} catch (ScriptException | NoSuchMethodException ex) {
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
}
}, delay);
}
public ScheduledFuture<?> scheduleAtTimestamp(final String methodName, long timestamp) {
return TimerManager.getInstance().scheduleAtTimestamp(() -> {
try {
iv.invokeFunction(methodName, (Object) null);
} catch (ScriptException | NoSuchMethodException ex) {
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
}
}, timestamp);
private void summonBoss(int mobId, int x, int y, String bgmName, String summonMessage) {
spawnMonster(mobId, x, y);
changeMusic(bgmName);
mapMessage(6, summonMessage);
}
public void dispelAllMonsters(int num, int team) { //dispels all mobs, cpq

View File

@@ -22,13 +22,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package scripting.reactor;
import client.MapleClient;
import jdk.nashorn.api.scripting.NashornScriptEngine;
import scripting.AbstractScriptManager;
import server.maps.MapleReactor;
import server.maps.ReactorDropEntry;
import tools.DatabaseConnection;
import tools.FilePrinter;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -42,22 +43,21 @@ import java.util.Map;
* @author Lerk
*/
public class ReactorScriptManager extends AbstractScriptManager {
private static ReactorScriptManager instance = new ReactorScriptManager();
private static final ReactorScriptManager instance = new ReactorScriptManager();
private final Map<Integer, List<ReactorDropEntry>> drops = new HashMap<>();
public static ReactorScriptManager getInstance() {
return instance;
}
private Map<Integer, List<ReactorDropEntry>> drops = new HashMap<>();
public void onHit(MapleClient c, MapleReactor reactor) {
try {
NashornScriptEngine iv = getScriptEngine("reactor/" + reactor.getId() + ".js", c);
if (iv == null) return;
ReactorActionManager rm = new ReactorActionManager(c, reactor, iv);
iv.put("rm", rm);
Invocable iv = initializeInvocable(c, reactor);
if (iv == null) {
return;
}
iv.invokeFunction("hit");
} catch (final NoSuchMethodException e) {} //do nothing, hit is OPTIONAL
@@ -68,11 +68,11 @@ public class ReactorScriptManager extends AbstractScriptManager {
public void act(MapleClient c, MapleReactor reactor) {
try {
NashornScriptEngine iv = getScriptEngine("reactor/" + reactor.getId() + ".js", c);
if (iv == null) return;
ReactorActionManager rm = new ReactorActionManager(c, reactor, iv);
iv.put("rm", rm);
Invocable iv = initializeInvocable(c, reactor);
if (iv == null) {
return;
}
iv.invokeFunction("act");
} catch (final ScriptException | NoSuchMethodException | NullPointerException e) {
FilePrinter.printError(FilePrinter.REACTOR + reactor.getId() + ".txt", e);
@@ -114,11 +114,11 @@ public class ReactorScriptManager extends AbstractScriptManager {
private void touching(MapleClient c, MapleReactor reactor, boolean touching) {
try {
NashornScriptEngine iv = getScriptEngine("reactor/" + reactor.getId() + ".js", c);
if (iv == null) return;
ReactorActionManager rm = new ReactorActionManager(c, reactor, iv);
iv.put("rm", rm);
Invocable iv = initializeInvocable(c, reactor);
if (iv == null) {
return;
}
if (touching) {
iv.invokeFunction("touch");
} else {
@@ -128,4 +128,17 @@ public class ReactorScriptManager extends AbstractScriptManager {
FilePrinter.printError(FilePrinter.REACTOR + reactor.getId() + ".txt", ute);
}
}
private Invocable initializeInvocable(MapleClient c, MapleReactor reactor) {
ScriptEngine engine = getInvocableScriptEngine("reactor/" + reactor.getId() + ".js", c);
if (engine == null) {
return null;
}
Invocable iv = (Invocable) engine;
ReactorActionManager rm = new ReactorActionManager(c, reactor, iv);
engine.put("rm", rm);
return iv;
}
}

View File

@@ -73,6 +73,7 @@ import java.sql.SQLException;
import java.util.List;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;
/**
*
@@ -1439,7 +1440,12 @@ public class MaplePacketCreator {
private static void encodeTemporary(MaplePacketLittleEndianWriter mplew, Map<MonsterStatus, MonsterStatusEffect> stati) {
int pCounter = -1, mCounter = -1;
stati = stati.entrySet() // to patch some status crashing players
.stream()
.filter(e -> !(e.getKey().equals(MonsterStatus.WATK) || e.getKey().equals(MonsterStatus.WDEF)))
.collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
writeLongEncodeTemporaryMask(mplew, stati.keySet()); // packet structure mapped thanks to Eric
for (Entry<MonsterStatus, MonsterStatusEffect> s : stati.entrySet()) {
@@ -2663,6 +2669,9 @@ public class MaplePacketCreator {
mplew.writeShort(SendOpcode.DAMAGE_PLAYER.getValue());
mplew.writeInt(cid);
mplew.write(skill);
if (skill == -3) {
mplew.writeInt(0);
}
mplew.writeInt(damage);
if(skill != -4) {
mplew.writeInt(monsteridfrom);