Using Java ThreadPool + Mob Skills & Event Instance patch + Eqp Merge

Server source now uses Java ThreadPool, recycling used thread resources for next uses.
Added Grenade visual effect for other players.
Implemented an attempt towards unsynced mob behavior, where reportedly players were able to pin same mob in different sections of the map.
Solved several deadlock issues, mostly regarding character synchronized methods, event instance scripts and player/item vision-unvision.
Solved an issue where mobs would not cast some skills of it's skillset. Frequent behavior on low-leveled mobs.
Fixed a bug on 2nd Maker quest where players could complete it by merely disassembling an equipment.
New custom mechanic: equipment merge. Similarly to the Bazaar NPC, every equipment after the selected one is used up, and a fraction of their stat amounts are used as stat gains on the currently equipped items. If restrictions are enabled, players must be high-leveled and Maker lv3 to use it.
Skill Storm Break no longer uses up arrows.
Added a server flag to allow access for all Aran job skills from the beginning.
Implemented Battleship and Super Transformation questline scripts.
Fixed a desynchronization within pet position and cash inventory position, that could potentially lead to some inventory issues until relogin.
Improved timestamp handling in some handler classes. Spam detection is entirely a server-side matter, hence removed usage of client-sided timestamp content.
Refactored some pet response packets, improving some of their behaviors.
Fixed some quest issues: Maker lv1 and Omega Sector meteorite one.
This commit is contained in:
ronancpl
2018-11-10 17:48:35 -02:00
parent 00675ab95d
commit 5ee0cd1c98
120 changed files with 7424 additions and 6387 deletions

View File

@@ -512,21 +512,21 @@ public class AbstractPlayerInteraction {
petId = MaplePet.createPet(id);
if(from != null) {
evolved = MaplePet.loadFromDb(id, (short) 0, petId);
evolved = MaplePet.loadFromDb(id, (short) 0, petId);
Point pos = getPlayer().getPosition();
pos.y -= 12;
evolved.setPos(pos);
evolved.setFh(getPlayer().getMap().getFootholds().findBelow(evolved.getPos()).getId());
evolved.setStance(0);
evolved.setSummoned(true);
Point pos = getPlayer().getPosition();
pos.y -= 12;
evolved.setPos(pos);
evolved.setFh(getPlayer().getMap().getFootholds().findBelow(evolved.getPos()).getId());
evolved.setStance(0);
evolved.setSummoned(true);
evolved.setName(from.getName().compareTo(MapleItemInformationProvider.getInstance().getName(from.getItemId())) != 0 ? from.getName() : MapleItemInformationProvider.getInstance().getName(id));
evolved.setCloseness(from.getCloseness());
evolved.setFullness(from.getFullness());
evolved.setLevel(from.getLevel());
evolved.setExpiration(System.currentTimeMillis() + expires);
evolved.saveToDb();
evolved.setName(from.getName().compareTo(MapleItemInformationProvider.getInstance().getName(from.getItemId())) != 0 ? from.getName() : MapleItemInformationProvider.getInstance().getName(id));
evolved.setCloseness(from.getCloseness());
evolved.setFullness(from.getFullness());
evolved.setLevel(from.getLevel());
evolved.setExpiration(System.currentTimeMillis() + expires);
evolved.saveToDb();
}
//MapleInventoryManipulator.addById(c, id, (short) 1, null, petId, expires == -1 ? -1 : System.currentTimeMillis() + expires);

View File

@@ -69,6 +69,7 @@ import net.server.coordinator.MapleEventRecallCoordinator;
import scripting.AbstractPlayerInteraction;
import scripting.event.worker.EventScriptScheduler;
import server.MapleItemInformationProvider;
import server.ThreadManager;
import server.life.MapleLifeFactory;
import server.life.MapleNPC;
import tools.MaplePacketCreator;
@@ -228,51 +229,42 @@ public class EventInstanceManager {
}
public synchronized void registerPlayer(MapleCharacter chr) {
public synchronized void registerPlayer(final MapleCharacter chr) {
if (chr == null || !chr.isLoggedinWorld() || disposed) {
return;
}
wL.lock();
try {
wL.lock();
try {
if(chars.containsKey(chr.getId())) {
return;
}
chars.put(chr.getId(), chr);
chr.setEventInstance(this);
} finally {
wL.unlock();
if(chars.containsKey(chr.getId())) {
return;
}
sL.lock();
try {
em.getIv().invokeFunction("playerEntry", this, chr);
} finally {
sL.unlock();
}
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
chars.put(chr.getId(), chr);
chr.setEventInstance(this);
} finally {
wL.unlock();
}
try {
em.getIv().invokeFunction("playerEntry", EventInstanceManager.this, chr);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
public void exitPlayer(MapleCharacter chr) {
public void exitPlayer(final MapleCharacter chr) {
if (chr == null || !chr.isLoggedin()){
return;
}
try {
unregisterPlayer(chr);
sL.lock();
try {
em.getIv().invokeFunction("playerExit", this, chr);
} finally {
sL.unlock();
}
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
unregisterPlayer(chr);
try {
em.getIv().invokeFunction("playerExit", EventInstanceManager.this, chr);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
public void dropMessage(int type, String message) {
@@ -297,15 +289,10 @@ public class EventInstanceManager {
event_schedule = TimerManager.getInstance().schedule(new Runnable() {
@Override
public void run() {
dismissEventTimer();
try {
dismissEventTimer();
sL.lock();
try {
em.getIv().invokeFunction("scheduledTimeout", EventInstanceManager.this);
} finally {
sL.unlock();
}
em.getIv().invokeFunction("scheduledTimeout", EventInstanceManager.this);
} catch (ScriptException | NoSuchMethodException ex) {
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, "Event '" + em.getName() + "' does not implement scheduledTimeout function.", ex);
}
@@ -314,31 +301,25 @@ public class EventInstanceManager {
}
public void addEventTimer(long time) {
if(event_schedule != null) {
if(event_schedule.cancel(false)) {
if (event_schedule != null) {
if (event_schedule.cancel(false)) {
long nextTime = getTimeLeft() + time;
eventTime += time;
event_schedule = TimerManager.getInstance().schedule(new Runnable() {
@Override
public void run() {
dismissEventTimer();
try {
dismissEventTimer();
sL.lock();
try {
em.getIv().invokeFunction("scheduledTimeout", EventInstanceManager.this);
} finally {
sL.unlock();
}
em.getIv().invokeFunction("scheduledTimeout", EventInstanceManager.this);
} catch (ScriptException | NoSuchMethodException ex) {
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, "Event '" + em.getName() + "' does not implement scheduledTimeout function.", ex);
}
}
}, nextTime);
}
}
else {
} else {
startEventTimer(time);
}
}
@@ -358,6 +339,7 @@ public class EventInstanceManager {
event_schedule.cancel(false);
event_schedule = null;
}
dismissEventTimer();
}
@@ -370,7 +352,7 @@ public class EventInstanceManager {
}
public void registerParty(MapleCharacter chr) {
if(chr.isPartyLeader()) {
if (chr.isPartyLeader()) {
registerParty(chr.getParty(), chr.getMap());
}
}
@@ -390,20 +372,16 @@ public class EventInstanceManager {
private void registerExpeditionTeam(MapleExpedition exped, int recruitMap) {
expedition = exped;
for(MapleCharacter chr: exped.getMembers()) {
if(chr.getMapId() == recruitMap)
for (MapleCharacter chr: exped.getMembers()) {
if (chr.getMapId() == recruitMap) {
registerPlayer(chr);
}
}
}
public void unregisterPlayer(MapleCharacter chr) {
public void unregisterPlayer(final MapleCharacter chr) {
try {
sL.lock();
try {
em.getIv().invokeFunction("playerUnregistered", EventInstanceManager.this, chr);
} finally {
sL.unlock();
}
em.getIv().invokeFunction("playerUnregistered", EventInstanceManager.this, chr);
} catch (ScriptException | NoSuchMethodException ex) {
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, "Event '" + em.getName() + "' does not implement playerUnregistered function.", ex);
}
@@ -462,180 +440,140 @@ public class EventInstanceManager {
}
}
public void movePlayer(MapleCharacter chr) {
try {
sL.lock();
try {
em.getIv().invokeFunction("moveMap", this, chr);
} finally {
sL.unlock();
}
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
public void changedMap(MapleCharacter chr, int mapId) {
try {
sL.lock();
try {
em.getIv().invokeFunction("changedMap", this, chr, mapId);
} finally {
sL.unlock();
}
} catch (ScriptException | NoSuchMethodException ex) {} // optional
}
public void afterChangedMap(MapleCharacter chr, int mapId) {
try {
sL.lock();
try {
em.getIv().invokeFunction("afterChangedMap", this, chr, mapId);
} finally {
sL.unlock();
}
} catch (ScriptException | NoSuchMethodException ex) {} // optional
}
public void changedLeader(MapleCharacter ldr) {
public void movePlayer(final MapleCharacter chr) {
try {
sL.lock();
try {
em.getIv().invokeFunction("changedLeader", this, ldr);
} finally {
sL.unlock();
}
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
em.getIv().invokeFunction("moveMap", EventInstanceManager.this, chr);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
public void changedMap(final MapleCharacter chr, final int mapId) {
try {
em.getIv().invokeFunction("changedMap", EventInstanceManager.this, chr, mapId);
} catch (ScriptException | NoSuchMethodException ex) {} // optional
}
public void afterChangedMap(final MapleCharacter chr, final int mapId) {
try {
em.getIv().invokeFunction("afterChangedMap", EventInstanceManager.this, chr, mapId);
} catch (ScriptException | NoSuchMethodException ex) {} // optional
}
public synchronized void changedLeader(final MapleCharacter ldr) {
try {
em.getIv().invokeFunction("changedLeader", EventInstanceManager.this, ldr);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
leaderId = ldr.getId();
}
public void monsterKilled(MapleMonster mob, boolean hasKiller) {
public void monsterKilled(final MapleMonster mob, final boolean hasKiller) {
int scriptResult = 0;
sL.lock();
try {
mobs.remove(mob);
if(eventStarted) {
try {
em.getIv().invokeFunction("monsterKilled", mob, this, hasKiller);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
scriptResult = 1;
if (mobs.isEmpty()) {
try {
em.getIv().invokeFunction("allMonstersDead", this, hasKiller);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
scriptResult = 2;
}
}
} finally {
sL.unlock();
}
if (scriptResult > 0) {
try {
em.getIv().invokeFunction("monsterKilled", mob, EventInstanceManager.this, hasKiller);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
if (scriptResult > 1) {
try {
em.getIv().invokeFunction("allMonstersDead", EventInstanceManager.this, hasKiller);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
}
}
public void friendlyKilled(MapleMonster mob, boolean hasKiller) {
try {
sL.lock();
try {
em.getIv().invokeFunction("friendlyKilled", mob, this, hasKiller);
} finally {
sL.unlock();
}
public void friendlyKilled(final MapleMonster mob, final boolean hasKiller) {
try {
em.getIv().invokeFunction("friendlyKilled", mob, EventInstanceManager.this, hasKiller);
} catch (ScriptException | NoSuchMethodException ex) {} //optional
}
public void playerKilled(MapleCharacter chr) {
try {
sL.lock();
try {
em.getIv().invokeFunction("playerDead", this, chr);
} finally {
sL.unlock();
public void playerKilled(final MapleCharacter chr) {
ThreadManager.getInstance().newTask(new Runnable() {
@Override
public void run() {
try {
em.getIv().invokeFunction("playerDead", EventInstanceManager.this, chr);
} catch (ScriptException | NoSuchMethodException ex) {} // optional
}
} catch (ScriptException | NoSuchMethodException ex) {} // optional
});
}
public void reviveMonster(MapleMonster mob) {
try {
sL.lock();
try {
em.getIv().invokeFunction("monsterRevive", this, mob);
} finally {
sL.unlock();
}
} catch (ScriptException | NoSuchMethodException ex) {} // optional
public void reviveMonster(final MapleMonster mob) {
try {
em.getIv().invokeFunction("monsterRevive", EventInstanceManager.this, mob);
} catch (ScriptException | NoSuchMethodException ex) {} // optional
}
public boolean revivePlayer(MapleCharacter chr) {
try {
Object b;
sL.lock();
try {
b = em.getIv().invokeFunction("playerRevive", this, chr);
} finally {
sL.unlock();
public boolean revivePlayer(final MapleCharacter chr) {
try {
Object b = em.getIv().invokeFunction("playerRevive", EventInstanceManager.this, chr);
if (b instanceof Boolean) {
return (Boolean) b;
}
if (b instanceof Boolean) {
return (Boolean) b;
}
} catch (ScriptException | NoSuchMethodException ex) {} // optional
} catch (ScriptException | NoSuchMethodException ex) {} // optional
return true;
}
public void playerDisconnected(MapleCharacter chr) {
try {
sL.lock();
try {
em.getIv().invokeFunction("playerDisconnected", this, chr);
} finally {
sL.unlock();
}
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
public void playerDisconnected(final MapleCharacter chr) {
try {
em.getIv().invokeFunction("playerDisconnected", EventInstanceManager.this, chr);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
MapleEventRecallCoordinator.getInstance().storeEventInstance(chr.getId(), this);
}
/**
*
* @param chr
* @param mob
*/
public void monsterKilled(MapleCharacter chr, MapleMonster mob) {
try {
Integer kc = killCount.get(chr);
public void monsterKilled(MapleCharacter chr, final MapleMonster mob) {
try {
int inc;
sL.lock();
try {
if(ServerConstants.JAVA_8)
inc = (int)em.getIv().invokeFunction("monsterValue", this, mob.getId());
else
inc = ((Double) em.getIv().invokeFunction("monsterValue", this, mob.getId())).intValue();
} finally {
sL.unlock();
if (ServerConstants.JAVA_8) {
inc = (int)em.getIv().invokeFunction("monsterValue", EventInstanceManager.this, mob.getId());
} else {
inc = ((Double) em.getIv().invokeFunction("monsterValue", EventInstanceManager.this, mob.getId())).intValue();
}
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();
}
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) {
@@ -650,15 +588,8 @@ public class EventInstanceManager {
} finally {
rL.unlock();
}
Thread t = new Thread( new Runnable() {
@Override
public void run() {
dispose(false);
}
});
t.start();
dispose(false);
}
public synchronized void dispose(boolean shutdown) { // should not trigger any event script method after disposed
@@ -666,16 +597,11 @@ public class EventInstanceManager {
disposed = true;
try {
sL.lock();
try {
em.getIv().invokeFunction("dispose", this);
} finally {
sL.unlock();
}
em.getIv().invokeFunction("dispose", EventInstanceManager.this);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
mapFactory.dispose();
ess.dispose();
@@ -738,13 +664,8 @@ public class EventInstanceManager {
@Override
public void run() {
try {
sL.lock();
try {
if(em == null) return;
em.getIv().invokeFunction(methodName, EventInstanceManager.this);
} finally {
sL.unlock();
}
if(em == null) return;
em.getIv().invokeFunction(methodName, EventInstanceManager.this);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
@@ -848,56 +769,36 @@ public class EventInstanceManager {
}
}
public void leftParty(MapleCharacter chr) {
try {
sL.lock();
try {
em.getIv().invokeFunction("leftParty", this, chr);
} finally {
sL.unlock();
}
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
public void leftParty(final MapleCharacter chr) {
try {
em.getIv().invokeFunction("leftParty", EventInstanceManager.this, chr);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
public void disbandParty() {
try {
sL.lock();
try {
em.getIv().invokeFunction("disbandParty", this);
} finally {
sL.unlock();
}
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
em.getIv().invokeFunction("disbandParty", EventInstanceManager.this);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
public void clearPQ() {
try {
sL.lock();
try {
em.getIv().invokeFunction("clearPQ", this);
} finally {
sL.unlock();
}
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
em.getIv().invokeFunction("clearPQ", EventInstanceManager.this);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
public void removePlayer(MapleCharacter chr) {
try {
sL.lock();
try {
em.getIv().invokeFunction("playerExit", this, chr);
} finally {
sL.unlock();
}
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
public void removePlayer(final MapleCharacter chr) {
try {
em.getIv().invokeFunction("playerExit", EventInstanceManager.this, chr);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
public boolean isLeader(MapleCharacter chr) {
@@ -1158,15 +1059,11 @@ public class EventInstanceManager {
}
}
public final void startEvent() {
public final synchronized void startEvent() {
eventStarted = true;
try {
sL.lock();
try {
eventStarted = true;
em.getIv().invokeFunction("afterSetup", this);
} finally {
sL.unlock();
}
em.getIv().invokeFunction("afterSetup", EventInstanceManager.this);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}

View File

@@ -60,6 +60,8 @@ import net.server.audit.LockCollector;
import net.server.audit.locks.MonitoredLockType;
import net.server.audit.locks.MonitoredReentrantLock;
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
import server.ThreadManager;
//import jdk.nashorn.api.scripting.ScriptUtils;
/**
*
@@ -647,12 +649,11 @@ public class EventManager {
if(p != null) {
List<MaplePartyCharacter> lmpc;
/*
if(ServerConstants.JAVA_8)
/*if(ServerConstants.JAVA_8) {
lmpc = new ArrayList<>(((Map<String, MaplePartyCharacter>)(ScriptUtils.convert(p, Map.class))).values());
else
} else {
lmpc = new ArrayList<>((List<MaplePartyCharacter>) p);
*/
}*/
lmpc = new ArrayList<>((List<MaplePartyCharacter>) p);
party.setEligibleMembers(lmpc);
@@ -809,8 +810,7 @@ public class EventManager {
}
private void fillEimQueue() {
Thread t = new Thread(new EventManagerWorker()); //call new thread to fill up readied instances queue
t.start();
ThreadManager.getInstance().newTask(new EventManagerWorker()); //call new thread to fill up readied instances queue
}
private EventInstanceManager getReadyInstance() {

View File

@@ -32,6 +32,7 @@ import net.server.audit.LockCollector;
import net.server.audit.locks.MonitoredLockType;
import net.server.audit.locks.MonitoredReentrantLock;
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
import server.ThreadManager;
/**
*
@@ -105,68 +106,62 @@ public class EventScriptScheduler {
public void registerEntry(final Runnable scheduledAction, final long duration) {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
schedulerLock.lock();
try {
idleProcs = 0;
if(schedulerTask == null) {
if(disposed) return;
ThreadManager.getInstance().newTask(new Runnable() {
@Override
public void run() {
schedulerLock.lock();
try {
idleProcs = 0;
if(schedulerTask == null) {
if(disposed) return;
schedulerTask = TimerManager.getInstance().register(monitorTask, ServerConstants.MOB_STATUS_MONITOR_PROC, ServerConstants.MOB_STATUS_MONITOR_PROC);
}
schedulerTask = TimerManager.getInstance().register(monitorTask, ServerConstants.MOB_STATUS_MONITOR_PROC, ServerConstants.MOB_STATUS_MONITOR_PROC);
}
registeredEntries.put(scheduledAction, Server.getInstance().getCurrentTime() + duration);
} finally {
schedulerLock.unlock();
}
}
});
t.start();
registeredEntries.put(scheduledAction, Server.getInstance().getCurrentTime() + duration);
} finally {
schedulerLock.unlock();
}
}
});
}
public void cancelEntry(final Runnable scheduledAction) {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
schedulerLock.lock();
try {
registeredEntries.remove(scheduledAction);
} finally {
schedulerLock.unlock();
}
}
});
t.start();
ThreadManager.getInstance().newTask(new Runnable() {
@Override
public void run() {
schedulerLock.lock();
try {
registeredEntries.remove(scheduledAction);
} finally {
schedulerLock.unlock();
}
}
});
}
public void dispose() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
schedulerLock.lock();
try {
if(schedulerTask != null) {
schedulerTask.cancel(false);
schedulerTask = null;
}
ThreadManager.getInstance().newTask(new Runnable() {
@Override
public void run() {
schedulerLock.lock();
try {
if(schedulerTask != null) {
schedulerTask.cancel(false);
schedulerTask = null;
}
registeredEntries.clear();
disposed = true;
} finally {
schedulerLock.unlock();
}
disposeLocks();
}
});
t.start();
registeredEntries.clear();
disposed = true;
} finally {
schedulerLock.unlock();
}
disposeLocks();
}
});
}
private void disposeLocks() {

View File

@@ -59,7 +59,7 @@ public class ItemScriptManager {
return scriptFile.exists();
}
public void getItemScript(MapleClient c, String scriptName) {
public void runItemScript(MapleClient c, String scriptName) {
if (scripts.containsKey(scriptName)) {
try {
scripts.get(scriptName).invokeFunction("start", new ItemScriptMethods(c));

View File

@@ -62,7 +62,7 @@ public class MapScriptManager {
return scriptFile.exists();
}
public void getMapScript(MapleClient c, String scriptName, boolean firstUser) {
public void runMapScript(MapleClient c, String scriptName, boolean firstUser) {
if (scripts.containsKey(scriptName)) {
try {
scripts.get(scriptName).invokeFunction("start", new MapScriptMethods(c));