Reformat and clean up "scripting" package
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -32,7 +32,6 @@ import java.io.FileReader;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Matze
|
* @author Matze
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractScriptManager {
|
public abstract class AbstractScriptManager {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -54,7 +54,6 @@ import java.util.logging.Logger;
|
|||||||
//import jdk.nashorn.api.scripting.ScriptUtils;
|
//import jdk.nashorn.api.scripting.ScriptUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Matze
|
* @author Matze
|
||||||
* @author Ronan
|
* @author Ronan
|
||||||
*/
|
*/
|
||||||
@@ -63,59 +62,61 @@ public class EventManager {
|
|||||||
private Channel cserv;
|
private Channel cserv;
|
||||||
private World wserv;
|
private World wserv;
|
||||||
private Server server;
|
private Server server;
|
||||||
private EventScriptScheduler ess = new EventScriptScheduler();
|
private final EventScriptScheduler ess = new EventScriptScheduler();
|
||||||
private Map<String, EventInstanceManager> instances = new HashMap<>();
|
private final Map<String, EventInstanceManager> instances = new HashMap<>();
|
||||||
private Map<String, Integer> instanceLocks = new HashMap<>();
|
private final Map<String, Integer> instanceLocks = new HashMap<>();
|
||||||
private final Queue<Integer> queuedGuilds = new LinkedList<>();
|
private final Queue<Integer> queuedGuilds = new LinkedList<>();
|
||||||
private final Map<Integer, Integer> queuedGuildLeaders = new HashMap<>();
|
private final Map<Integer, Integer> queuedGuildLeaders = new HashMap<>();
|
||||||
private List<Boolean> openedLobbys;
|
private final List<Boolean> openedLobbys;
|
||||||
private List<EventInstanceManager> readyInstances = new LinkedList<>();
|
private final List<EventInstanceManager> readyInstances = new LinkedList<>();
|
||||||
private Integer readyId = 0, onLoadInstances = 0;
|
private Integer readyId = 0, onLoadInstances = 0;
|
||||||
private Properties props = new Properties();
|
private final Properties props = new Properties();
|
||||||
private String name;
|
private final String name;
|
||||||
private MonitoredReentrantLock lobbyLock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.EM_LOBBY);
|
private MonitoredReentrantLock lobbyLock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.EM_LOBBY);
|
||||||
private MonitoredReentrantLock queueLock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.EM_QUEUE);
|
private MonitoredReentrantLock queueLock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.EM_QUEUE);
|
||||||
private MonitoredReentrantLock startLock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.EM_START);
|
private MonitoredReentrantLock startLock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.EM_START);
|
||||||
|
|
||||||
private Set<Integer> playerPermit = new HashSet<>();
|
private final Set<Integer> playerPermit = new HashSet<>();
|
||||||
private Semaphore startSemaphore = new Semaphore(7);
|
private final Semaphore startSemaphore = new Semaphore(7);
|
||||||
|
|
||||||
private static final int maxLobbys = 8; // an event manager holds up to this amount of concurrent lobbys
|
private static final int maxLobbys = 8; // an event manager holds up to this amount of concurrent lobbys
|
||||||
|
|
||||||
public EventManager(Channel cserv, Invocable iv, String name) {
|
public EventManager(Channel cserv, Invocable iv, String name) {
|
||||||
this.server = Server.getInstance();
|
this.server = Server.getInstance();
|
||||||
this.iv = iv;
|
this.iv = iv;
|
||||||
this.cserv = cserv;
|
this.cserv = cserv;
|
||||||
this.wserv = server.getWorld(cserv.getWorld());
|
this.wserv = server.getWorld(cserv.getWorld());
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
this.openedLobbys = new ArrayList<>();
|
this.openedLobbys = new ArrayList<>();
|
||||||
for(int i = 0; i < maxLobbys; i++) this.openedLobbys.add(false);
|
for (int i = 0; i < maxLobbys; i++) {
|
||||||
|
this.openedLobbys.add(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDisposed() {
|
private boolean isDisposed() {
|
||||||
return onLoadInstances <= -1000;
|
return onLoadInstances <= -1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancel() { // make sure to only call this when there are NO PLAYERS ONLINE to mess around with the event manager!
|
public void cancel() { // make sure to only call this when there are NO PLAYERS ONLINE to mess around with the event manager!
|
||||||
ess.dispose();
|
ess.dispose();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
iv.invokeFunction("cancelSchedule", (Object) null);
|
iv.invokeFunction("cancelSchedule", (Object) null);
|
||||||
} catch (ScriptException | NoSuchMethodException ex) {
|
} catch (ScriptException | NoSuchMethodException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
Collection<EventInstanceManager> eimList;
|
Collection<EventInstanceManager> eimList;
|
||||||
synchronized(instances) {
|
synchronized (instances) {
|
||||||
eimList = getInstances();
|
eimList = getInstances();
|
||||||
instances.clear();
|
instances.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
for(EventInstanceManager eim : eimList) {
|
for (EventInstanceManager eim : eimList) {
|
||||||
eim.dispose(true);
|
eim.dispose(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<EventInstanceManager> readyEims;
|
List<EventInstanceManager> readyEims;
|
||||||
queueLock.lock();
|
queueLock.lock();
|
||||||
try {
|
try {
|
||||||
@@ -125,24 +126,24 @@ public class EventManager {
|
|||||||
} finally {
|
} finally {
|
||||||
queueLock.unlock();
|
queueLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
for(EventInstanceManager eim : readyEims) {
|
for (EventInstanceManager eim : readyEims) {
|
||||||
eim.dispose(true);
|
eim.dispose(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
props.clear();
|
props.clear();
|
||||||
cserv = null;
|
cserv = null;
|
||||||
wserv = null;
|
wserv = null;
|
||||||
server = null;
|
server = null;
|
||||||
iv = null;
|
iv = null;
|
||||||
|
|
||||||
disposeLocks();
|
disposeLocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disposeLocks() {
|
private void disposeLocks() {
|
||||||
LockCollector.getInstance().registerDisposeAction(() -> emptyLocks());
|
LockCollector.getInstance().registerDisposeAction(() -> emptyLocks());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void emptyLocks() {
|
private void emptyLocks() {
|
||||||
lobbyLock = lobbyLock.dispose();
|
lobbyLock = lobbyLock.dispose();
|
||||||
queueLock = queueLock.dispose();
|
queueLock = queueLock.dispose();
|
||||||
@@ -158,11 +159,11 @@ public class EventManager {
|
|||||||
|
|
||||||
return intList;
|
return intList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLobbyDelay() {
|
public long getLobbyDelay() {
|
||||||
return YamlConfig.config.server.EVENT_LOBBY_DELAY;
|
return YamlConfig.config.server.EVENT_LOBBY_DELAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getMaxLobbies() {
|
private int getMaxLobbies() {
|
||||||
try {
|
try {
|
||||||
return (int) iv.invokeFunction("getMaxLobbies");
|
return (int) iv.invokeFunction("getMaxLobbies");
|
||||||
@@ -183,9 +184,9 @@ public class EventManager {
|
|||||||
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ess.registerEntry(r, delay);
|
ess.registerEntry(r, delay);
|
||||||
|
|
||||||
// hate to do that, but those schedules can still be cancelled, so well... Let GC do it's job
|
// hate to do that, but those schedules can still be cancelled, so well... Let GC do it's job
|
||||||
return new EventScheduledFuture(r, ess);
|
return new EventScheduledFuture(r, ess);
|
||||||
}
|
}
|
||||||
@@ -198,7 +199,7 @@ public class EventManager {
|
|||||||
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ess.registerEntry(r, timestamp - server.getCurrentTime());
|
ess.registerEntry(r, timestamp - server.getCurrentTime());
|
||||||
return new EventScheduledFuture(r, ess);
|
return new EventScheduledFuture(r, ess);
|
||||||
}
|
}
|
||||||
@@ -206,11 +207,11 @@ public class EventManager {
|
|||||||
public World getWorldServer() {
|
public World getWorldServer() {
|
||||||
return wserv;
|
return wserv;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Channel getChannelServer() {
|
public Channel getChannelServer() {
|
||||||
return cserv;
|
return cserv;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Invocable getIv() {
|
public Invocable getIv() {
|
||||||
return iv;
|
return iv;
|
||||||
}
|
}
|
||||||
@@ -227,31 +228,31 @@ public class EventManager {
|
|||||||
|
|
||||||
public EventInstanceManager newInstance(String name) throws EventInstanceInProgressException {
|
public EventInstanceManager newInstance(String name) throws EventInstanceInProgressException {
|
||||||
EventInstanceManager ret = getReadyInstance();
|
EventInstanceManager ret = getReadyInstance();
|
||||||
|
|
||||||
if(ret == null) {
|
if (ret == null) {
|
||||||
ret = new EventInstanceManager(this, name);
|
ret = new EventInstanceManager(this, name);
|
||||||
} else {
|
} else {
|
||||||
ret.setName(name);
|
ret.setName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (instances) {
|
synchronized (instances) {
|
||||||
if (instances.containsKey(name)) {
|
if (instances.containsKey(name)) {
|
||||||
throw new EventInstanceInProgressException(name, this.getName());
|
throw new EventInstanceInProgressException(name, this.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
instances.put(name, ret);
|
instances.put(name, ret);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Marriage newMarriage(String name) throws EventInstanceInProgressException {
|
public Marriage newMarriage(String name) throws EventInstanceInProgressException {
|
||||||
Marriage ret = new Marriage(this, name);
|
Marriage ret = new Marriage(this, name);
|
||||||
|
|
||||||
synchronized (instances) {
|
synchronized (instances) {
|
||||||
if (instances.containsKey(name)) {
|
if (instances.containsKey(name)) {
|
||||||
throw new EventInstanceInProgressException(name, this.getName());
|
throw new EventInstanceInProgressException(name, this.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
instances.put(name, ret);
|
instances.put(name, ret);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
@@ -270,11 +271,11 @@ public class EventManager {
|
|||||||
public void setProperty(String key, String value) {
|
public void setProperty(String key, String value) {
|
||||||
props.setProperty(key, value);
|
props.setProperty(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIntProperty(String key, int value) {
|
public void setIntProperty(String key, int value) {
|
||||||
setProperty(key, value);
|
setProperty(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProperty(String key, int value) {
|
public void setProperty(String key, int value) {
|
||||||
props.setProperty(key, value + "");
|
props.setProperty(key, value + "");
|
||||||
}
|
}
|
||||||
@@ -282,11 +283,11 @@ public class EventManager {
|
|||||||
public String getProperty(String key) {
|
public String getProperty(String key) {
|
||||||
return props.getProperty(key);
|
return props.getProperty(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getIntProperty(String key) {
|
public int getIntProperty(String key) {
|
||||||
return Integer.parseInt(props.getProperty(key));
|
return Integer.parseInt(props.getProperty(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setLockLobby(int lobbyId, boolean lock) {
|
private void setLockLobby(int lobbyId, boolean lock) {
|
||||||
lobbyLock.lock();
|
lobbyLock.lock();
|
||||||
try {
|
try {
|
||||||
@@ -295,7 +296,7 @@ public class EventManager {
|
|||||||
lobbyLock.unlock();
|
lobbyLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean startLobbyInstance(int lobbyId) {
|
private boolean startLobbyInstance(int lobbyId) {
|
||||||
lobbyLock.lock();
|
lobbyLock.lock();
|
||||||
try {
|
try {
|
||||||
@@ -304,24 +305,28 @@ public class EventManager {
|
|||||||
} else if (lobbyId >= maxLobbys) {
|
} else if (lobbyId >= maxLobbys) {
|
||||||
lobbyId = maxLobbys - 1;
|
lobbyId = maxLobbys - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!openedLobbys.get(lobbyId)) {
|
if (!openedLobbys.get(lobbyId)) {
|
||||||
openedLobbys.set(lobbyId, true);
|
openedLobbys.set(lobbyId, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
lobbyLock.unlock();
|
lobbyLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void freeLobbyInstance(String lobbyName) {
|
private void freeLobbyInstance(String lobbyName) {
|
||||||
Integer i = instanceLocks.get(lobbyName);
|
Integer i = instanceLocks.get(lobbyName);
|
||||||
if(i == null) return;
|
if (i == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
instanceLocks.remove(lobbyName);
|
instanceLocks.remove(lobbyName);
|
||||||
if(i > -1) setLockLobby(i, false);
|
if (i > -1) {
|
||||||
|
setLockLobby(i, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -341,62 +346,67 @@ public class EventManager {
|
|||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getInternalScriptExceptionMessage(Throwable a) {
|
private String getInternalScriptExceptionMessage(Throwable a) {
|
||||||
if (!(a instanceof ScriptException)) {
|
if (!(a instanceof ScriptException)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(true) {
|
while (true) {
|
||||||
Throwable t = a;
|
Throwable t = a;
|
||||||
a = a.getCause();
|
a = a.getCause();
|
||||||
|
|
||||||
if (a == null) {
|
if (a == null) {
|
||||||
return t.getMessage();
|
return t.getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private EventInstanceManager createInstance(String name, Object... args) throws ScriptException, NoSuchMethodException {
|
private EventInstanceManager createInstance(String name, Object... args) throws ScriptException, NoSuchMethodException {
|
||||||
return (EventInstanceManager) iv.invokeFunction(name, args);
|
return (EventInstanceManager) iv.invokeFunction(name, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerEventInstance(String eventName, int lobbyId) {
|
private void registerEventInstance(String eventName, int lobbyId) {
|
||||||
Integer oldLobby = instanceLocks.get(eventName);
|
Integer oldLobby = instanceLocks.get(eventName);
|
||||||
if (oldLobby != null) {
|
if (oldLobby != null) {
|
||||||
setLockLobby(oldLobby, false);
|
setLockLobby(oldLobby, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
instanceLocks.put(eventName, lobbyId);
|
instanceLocks.put(eventName, lobbyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean startInstance(Expedition exped) {
|
public boolean startInstance(Expedition exped) {
|
||||||
return startInstance(-1, exped);
|
return startInstance(-1, exped);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean startInstance(int lobbyId, Expedition exped) {
|
public boolean startInstance(int lobbyId, Expedition exped) {
|
||||||
return startInstance(lobbyId, exped, exped.getLeader());
|
return startInstance(lobbyId, exped, exped.getLeader());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Expedition method: starts an expedition
|
//Expedition method: starts an expedition
|
||||||
public boolean startInstance(int lobbyId, Expedition exped, Character leader) {
|
public boolean startInstance(int lobbyId, Expedition exped, Character leader) {
|
||||||
if (this.isDisposed()) return false;
|
if (this.isDisposed()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if(!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
|
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
|
||||||
playerPermit.add(leader.getId());
|
playerPermit.add(leader.getId());
|
||||||
|
|
||||||
startLock.lock();
|
startLock.lock();
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
if(lobbyId == -1) {
|
if (lobbyId == -1) {
|
||||||
lobbyId = availableLobbyInstance();
|
lobbyId = availableLobbyInstance();
|
||||||
if(lobbyId == -1) return false;
|
if (lobbyId == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!startLobbyInstance(lobbyId)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
if(!startLobbyInstance(lobbyId)) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
EventInstanceManager eim;
|
EventInstanceManager eim;
|
||||||
try {
|
try {
|
||||||
eim = createInstance("setup", leader.getClient().getChannel());
|
eim = createInstance("setup", leader.getClient().getChannel());
|
||||||
@@ -406,13 +416,13 @@ public class EventManager {
|
|||||||
if (message != null && !message.startsWith(EventInstanceInProgressException.EIIP_KEY)) {
|
if (message != null && !message.startsWith(EventInstanceInProgressException.EIIP_KEY)) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(lobbyId > -1) {
|
if (lobbyId > -1) {
|
||||||
setLockLobby(lobbyId, false);
|
setLockLobby(lobbyId, false);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
eim.setLeader(leader);
|
eim.setLeader(leader);
|
||||||
|
|
||||||
exped.start();
|
exped.start();
|
||||||
@@ -430,10 +440,10 @@ public class EventManager {
|
|||||||
startSemaphore.release();
|
startSemaphore.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
playerPermit.remove(leader.getId());
|
playerPermit.remove(leader.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -441,33 +451,34 @@ public class EventManager {
|
|||||||
public boolean startInstance(Character chr) {
|
public boolean startInstance(Character chr) {
|
||||||
return startInstance(-1, chr);
|
return startInstance(-1, chr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean startInstance(int lobbyId, Character leader) {
|
public boolean startInstance(int lobbyId, Character leader) {
|
||||||
return startInstance(lobbyId, leader, leader, 1);
|
return startInstance(lobbyId, leader, leader, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean startInstance(int lobbyId, Character chr, Character leader, int difficulty) {
|
public boolean startInstance(int lobbyId, Character chr, Character leader, int difficulty) {
|
||||||
if (this.isDisposed()) return false;
|
if (this.isDisposed()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if(!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
|
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
|
||||||
playerPermit.add(leader.getId());
|
playerPermit.add(leader.getId());
|
||||||
|
|
||||||
startLock.lock();
|
startLock.lock();
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
if(lobbyId == -1) {
|
if (lobbyId == -1) {
|
||||||
lobbyId = availableLobbyInstance();
|
lobbyId = availableLobbyInstance();
|
||||||
if(lobbyId == -1) {
|
if (lobbyId == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!startLobbyInstance(lobbyId)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
if(!startLobbyInstance(lobbyId)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
EventInstanceManager eim;
|
EventInstanceManager eim;
|
||||||
try {
|
try {
|
||||||
eim = createInstance("setup", difficulty, (lobbyId > -1) ? lobbyId : leader.getId());
|
eim = createInstance("setup", difficulty, (lobbyId > -1) ? lobbyId : leader.getId());
|
||||||
@@ -477,15 +488,17 @@ public class EventManager {
|
|||||||
if (message != null && !message.startsWith(EventInstanceInProgressException.EIIP_KEY)) {
|
if (message != null && !message.startsWith(EventInstanceInProgressException.EIIP_KEY)) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(lobbyId > -1) {
|
if (lobbyId > -1) {
|
||||||
setLockLobby(lobbyId, false);
|
setLockLobby(lobbyId, false);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
eim.setLeader(leader);
|
eim.setLeader(leader);
|
||||||
|
|
||||||
if(chr != null) eim.registerPlayer(chr);
|
if (chr != null) {
|
||||||
|
eim.registerPlayer(chr);
|
||||||
|
}
|
||||||
|
|
||||||
eim.startEvent();
|
eim.startEvent();
|
||||||
} catch (ScriptException | NoSuchMethodException ex) {
|
} catch (ScriptException | NoSuchMethodException ex) {
|
||||||
@@ -499,40 +512,45 @@ public class EventManager {
|
|||||||
startSemaphore.release();
|
startSemaphore.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
playerPermit.remove(leader.getId());
|
playerPermit.remove(leader.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//PQ method: starts a PQ
|
//PQ method: starts a PQ
|
||||||
public boolean startInstance(Party party, MapleMap map) {
|
public boolean startInstance(Party party, MapleMap map) {
|
||||||
return startInstance(-1, party, map);
|
return startInstance(-1, party, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean startInstance(int lobbyId, Party party, MapleMap map) {
|
public boolean startInstance(int lobbyId, Party party, MapleMap map) {
|
||||||
return startInstance(lobbyId, party, map, party.getLeader().getPlayer());
|
return startInstance(lobbyId, party, map, party.getLeader().getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean startInstance(int lobbyId, Party party, MapleMap map, Character leader) {
|
public boolean startInstance(int lobbyId, Party party, MapleMap map, Character leader) {
|
||||||
if (this.isDisposed()) return false;
|
if (this.isDisposed()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if(!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
|
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
|
||||||
playerPermit.add(leader.getId());
|
playerPermit.add(leader.getId());
|
||||||
|
|
||||||
startLock.lock();
|
startLock.lock();
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
if(lobbyId == -1) {
|
if (lobbyId == -1) {
|
||||||
lobbyId = availableLobbyInstance();
|
lobbyId = availableLobbyInstance();
|
||||||
if(lobbyId == -1) return false;
|
if (lobbyId == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!startLobbyInstance(lobbyId)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
if(!startLobbyInstance(lobbyId)) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
EventInstanceManager eim;
|
EventInstanceManager eim;
|
||||||
try {
|
try {
|
||||||
eim = createInstance("setup", (Object) null);
|
eim = createInstance("setup", (Object) null);
|
||||||
@@ -542,13 +560,13 @@ public class EventManager {
|
|||||||
if (message != null && !message.startsWith(EventInstanceInProgressException.EIIP_KEY)) {
|
if (message != null && !message.startsWith(EventInstanceInProgressException.EIIP_KEY)) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(lobbyId > -1) {
|
if (lobbyId > -1) {
|
||||||
setLockLobby(lobbyId, false);
|
setLockLobby(lobbyId, false);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
eim.setLeader(leader);
|
eim.setLeader(leader);
|
||||||
|
|
||||||
eim.registerParty(party, map);
|
eim.registerParty(party, map);
|
||||||
@@ -566,40 +584,45 @@ public class EventManager {
|
|||||||
startSemaphore.release();
|
startSemaphore.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
playerPermit.remove(leader.getId());
|
playerPermit.remove(leader.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//PQ method: starts a PQ with a difficulty level, requires function setup(difficulty, leaderid) instead of setup()
|
//PQ method: starts a PQ with a difficulty level, requires function setup(difficulty, leaderid) instead of setup()
|
||||||
public boolean startInstance(Party party, MapleMap map, int difficulty) {
|
public boolean startInstance(Party party, MapleMap map, int difficulty) {
|
||||||
return startInstance(-1, party, map, difficulty);
|
return startInstance(-1, party, map, difficulty);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean startInstance(int lobbyId, Party party, MapleMap map, int difficulty) {
|
public boolean startInstance(int lobbyId, Party party, MapleMap map, int difficulty) {
|
||||||
return startInstance(lobbyId, party, map, difficulty, party.getLeader().getPlayer());
|
return startInstance(lobbyId, party, map, difficulty, party.getLeader().getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean startInstance(int lobbyId, Party party, MapleMap map, int difficulty, Character leader) {
|
public boolean startInstance(int lobbyId, Party party, MapleMap map, int difficulty, Character leader) {
|
||||||
if (this.isDisposed()) return false;
|
if (this.isDisposed()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if(!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
|
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
|
||||||
playerPermit.add(leader.getId());
|
playerPermit.add(leader.getId());
|
||||||
|
|
||||||
startLock.lock();
|
startLock.lock();
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
if(lobbyId == -1) {
|
if (lobbyId == -1) {
|
||||||
lobbyId = availableLobbyInstance();
|
lobbyId = availableLobbyInstance();
|
||||||
if(lobbyId == -1) return false;
|
if (lobbyId == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!startLobbyInstance(lobbyId)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
if(!startLobbyInstance(lobbyId)) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
EventInstanceManager eim;
|
EventInstanceManager eim;
|
||||||
try {
|
try {
|
||||||
eim = createInstance("setup", difficulty, (lobbyId > -1) ? lobbyId : party.getLeaderId());
|
eim = createInstance("setup", difficulty, (lobbyId > -1) ? lobbyId : party.getLeaderId());
|
||||||
@@ -609,13 +632,13 @@ public class EventManager {
|
|||||||
if (message != null && !message.startsWith(EventInstanceInProgressException.EIIP_KEY)) {
|
if (message != null && !message.startsWith(EventInstanceInProgressException.EIIP_KEY)) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(lobbyId > -1) {
|
if (lobbyId > -1) {
|
||||||
setLockLobby(lobbyId, false);
|
setLockLobby(lobbyId, false);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
eim.setLeader(leader);
|
eim.setLeader(leader);
|
||||||
|
|
||||||
eim.registerParty(party, map);
|
eim.registerParty(party, map);
|
||||||
@@ -633,10 +656,10 @@ public class EventManager {
|
|||||||
startSemaphore.release();
|
startSemaphore.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
playerPermit.remove(leader.getId());
|
playerPermit.remove(leader.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -644,35 +667,40 @@ public class EventManager {
|
|||||||
public boolean startInstance(EventInstanceManager eim, String ldr) {
|
public boolean startInstance(EventInstanceManager eim, String ldr) {
|
||||||
return startInstance(-1, eim, ldr);
|
return startInstance(-1, eim, ldr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean startInstance(EventInstanceManager eim, Character ldr) {
|
public boolean startInstance(EventInstanceManager eim, Character ldr) {
|
||||||
return startInstance(-1, eim, ldr.getName(), ldr);
|
return startInstance(-1, eim, ldr.getName(), ldr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean startInstance(int lobbyId, EventInstanceManager eim, String ldr) {
|
public boolean startInstance(int lobbyId, EventInstanceManager eim, String ldr) {
|
||||||
return startInstance(-1, eim, ldr, eim.getEm().getChannelServer().getPlayerStorage().getCharacterByName(ldr)); // things they make me do...
|
return startInstance(-1, eim, ldr, eim.getEm().getChannelServer().getPlayerStorage().getCharacterByName(ldr)); // things they make me do...
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean startInstance(int lobbyId, EventInstanceManager eim, String ldr, Character leader) {
|
public boolean startInstance(int lobbyId, EventInstanceManager eim, String ldr, Character leader) {
|
||||||
if (this.isDisposed()) return false;
|
if (this.isDisposed()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if(!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
|
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
|
||||||
playerPermit.add(leader.getId());
|
playerPermit.add(leader.getId());
|
||||||
|
|
||||||
startLock.lock();
|
startLock.lock();
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
if(lobbyId == -1) {
|
if (lobbyId == -1) {
|
||||||
lobbyId = availableLobbyInstance();
|
lobbyId = availableLobbyInstance();
|
||||||
if(lobbyId == -1) return false;
|
if (lobbyId == -1) {
|
||||||
}
|
return false;
|
||||||
else {
|
}
|
||||||
if(!startLobbyInstance(lobbyId)) return false;
|
} else {
|
||||||
|
if (!startLobbyInstance(lobbyId)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(eim == null) {
|
if (eim == null) {
|
||||||
if(lobbyId > -1) {
|
if (lobbyId > -1) {
|
||||||
setLockLobby(lobbyId, false);
|
setLockLobby(lobbyId, false);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -695,20 +723,20 @@ public class EventManager {
|
|||||||
startSemaphore.release();
|
startSemaphore.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
playerPermit.remove(leader.getId());
|
playerPermit.remove(leader.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PartyCharacter> getEligibleParty(Party party) {
|
public List<PartyCharacter> getEligibleParty(Party party) {
|
||||||
if (party == null) {
|
if (party == null) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Object o = iv.invokeFunction("getEligibleParty", party.getPartyMembersOnline());
|
Object o = iv.invokeFunction("getEligibleParty", party.getPartyMembersOnline());
|
||||||
|
|
||||||
if (o instanceof PartyCharacter[] partyChrs) {
|
if (o instanceof PartyCharacter[] partyChrs) {
|
||||||
final List<PartyCharacter> eligibleParty = new ArrayList<>(Arrays.asList(partyChrs));
|
final List<PartyCharacter> eligibleParty = new ArrayList<>(Arrays.asList(partyChrs));
|
||||||
party.setEligibleMembers(eligibleParty);
|
party.setEligibleMembers(eligibleParty);
|
||||||
@@ -720,7 +748,7 @@ public class EventManager {
|
|||||||
|
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearPQ(EventInstanceManager eim) {
|
public void clearPQ(EventInstanceManager eim) {
|
||||||
try {
|
try {
|
||||||
iv.invokeFunction("clearPQ", eim);
|
iv.invokeFunction("clearPQ", eim);
|
||||||
@@ -728,7 +756,7 @@ public class EventManager {
|
|||||||
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearPQ(EventInstanceManager eim, MapleMap toMap) {
|
public void clearPQ(EventInstanceManager eim, MapleMap toMap) {
|
||||||
try {
|
try {
|
||||||
iv.invokeFunction("clearPQ", eim, toMap);
|
iv.invokeFunction("clearPQ", eim, toMap);
|
||||||
@@ -736,66 +764,71 @@ public class EventManager {
|
|||||||
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Monster getMonster(int mid) {
|
public Monster getMonster(int mid) {
|
||||||
return(LifeFactory.getMonster(mid));
|
return (LifeFactory.getMonster(mid));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exportReadyGuild(Integer guildId) {
|
private void exportReadyGuild(Integer guildId) {
|
||||||
Guild mg = server.getGuild(guildId);
|
Guild mg = server.getGuild(guildId);
|
||||||
String callout = "[Guild Quest] Your guild has been registered to attend to the Sharenian Guild Quest at channel " + this.getChannelServer().getId()
|
String callout = "[Guild Quest] Your guild has been registered to attend to the Sharenian Guild Quest at channel " + this.getChannelServer().getId()
|
||||||
+ " and HAS JUST STARTED THE STRATEGY PHASE. After 3 minutes, no more guild members will be allowed to join the effort."
|
+ " and HAS JUST STARTED THE STRATEGY PHASE. After 3 minutes, no more guild members will be allowed to join the effort."
|
||||||
+ " Check out Shuang at the excavation site in Perion for more info.";
|
+ " Check out Shuang at the excavation site in Perion for more info.";
|
||||||
|
|
||||||
mg.dropMessage(6, callout);
|
mg.dropMessage(6, callout);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exportMovedQueueToGuild(Integer guildId, int place) {
|
private void exportMovedQueueToGuild(Integer guildId, int place) {
|
||||||
Guild mg = server.getGuild(guildId);
|
Guild mg = server.getGuild(guildId);
|
||||||
String callout = "[Guild Quest] Your guild has been registered to attend to the Sharenian Guild Quest at channel " + this.getChannelServer().getId()
|
String callout = "[Guild Quest] Your guild has been registered to attend to the Sharenian Guild Quest at channel " + this.getChannelServer().getId()
|
||||||
+ " and is currently on the " + GameConstants.ordinal(place) + " place on the waiting queue.";
|
+ " and is currently on the " + GameConstants.ordinal(place) + " place on the waiting queue.";
|
||||||
|
|
||||||
mg.dropMessage(6, callout);
|
mg.dropMessage(6, callout);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Integer> getNextGuildQueue() {
|
private List<Integer> getNextGuildQueue() {
|
||||||
synchronized(queuedGuilds) {
|
synchronized (queuedGuilds) {
|
||||||
Integer guildId = queuedGuilds.poll();
|
Integer guildId = queuedGuilds.poll();
|
||||||
if(guildId == null) return null;
|
if (guildId == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
wserv.removeGuildQueued(guildId);
|
wserv.removeGuildQueued(guildId);
|
||||||
Integer leaderId = queuedGuildLeaders.remove(guildId);
|
Integer leaderId = queuedGuildLeaders.remove(guildId);
|
||||||
|
|
||||||
int place = 1;
|
int place = 1;
|
||||||
for(Integer i: queuedGuilds) {
|
for (Integer i : queuedGuilds) {
|
||||||
exportMovedQueueToGuild(i, place);
|
exportMovedQueueToGuild(i, place);
|
||||||
place++;
|
place++;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Integer> list = new ArrayList<>(2);
|
List<Integer> list = new ArrayList<>(2);
|
||||||
list.add(guildId); list.add(leaderId);
|
list.add(guildId);
|
||||||
|
list.add(leaderId);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isQueueFull() {
|
public boolean isQueueFull() {
|
||||||
synchronized(queuedGuilds) {
|
synchronized (queuedGuilds) {
|
||||||
return queuedGuilds.size() >= YamlConfig.config.server.EVENT_MAX_GUILD_QUEUE;
|
return queuedGuilds.size() >= YamlConfig.config.server.EVENT_MAX_GUILD_QUEUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getQueueSize() {
|
public int getQueueSize() {
|
||||||
synchronized(queuedGuilds) {
|
synchronized (queuedGuilds) {
|
||||||
return queuedGuilds.size();
|
return queuedGuilds.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte addGuildToQueue(Integer guildId, Integer leaderId) {
|
public byte addGuildToQueue(Integer guildId, Integer leaderId) {
|
||||||
if(wserv.isGuildQueued(guildId)) return -1;
|
if (wserv.isGuildQueued(guildId)) {
|
||||||
|
return -1;
|
||||||
if(!isQueueFull()) {
|
}
|
||||||
|
|
||||||
|
if (!isQueueFull()) {
|
||||||
boolean canStartAhead;
|
boolean canStartAhead;
|
||||||
synchronized(queuedGuilds) {
|
synchronized (queuedGuilds) {
|
||||||
canStartAhead = queuedGuilds.isEmpty();
|
canStartAhead = queuedGuilds.isEmpty();
|
||||||
|
|
||||||
queuedGuilds.add(guildId);
|
queuedGuilds.add(guildId);
|
||||||
@@ -805,10 +838,10 @@ public class EventManager {
|
|||||||
int place = queuedGuilds.size();
|
int place = queuedGuilds.size();
|
||||||
exportMovedQueueToGuild(guildId, place);
|
exportMovedQueueToGuild(guildId, place);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(canStartAhead) {
|
if (canStartAhead) {
|
||||||
if(!attemptStartGuildInstance()) {
|
if (!attemptStartGuildInstance()) {
|
||||||
synchronized(queuedGuilds) {
|
synchronized (queuedGuilds) {
|
||||||
queuedGuilds.add(guildId);
|
queuedGuilds.add(guildId);
|
||||||
wserv.putGuildQueued(guildId);
|
wserv.putGuildQueued(guildId);
|
||||||
queuedGuildLeaders.put(guildId, leaderId);
|
queuedGuildLeaders.put(guildId, leaderId);
|
||||||
@@ -817,33 +850,33 @@ public class EventManager {
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean attemptStartGuildInstance() {
|
public boolean attemptStartGuildInstance() {
|
||||||
Character chr = null;
|
Character chr = null;
|
||||||
List<Integer> guildInstance = null;
|
List<Integer> guildInstance = null;
|
||||||
while(chr == null) {
|
while (chr == null) {
|
||||||
guildInstance = getNextGuildQueue();
|
guildInstance = getNextGuildQueue();
|
||||||
if(guildInstance == null) {
|
if (guildInstance == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
chr = cserv.getPlayerStorage().getCharacterById(guildInstance.get(1));
|
chr = cserv.getPlayerStorage().getCharacterById(guildInstance.get(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(startInstance(chr)) {
|
if (startInstance(chr)) {
|
||||||
exportReadyGuild(guildInstance.get(0));
|
exportReadyGuild(guildInstance.get(0));
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startQuest(Character chr, int id, int npcid) {
|
public void startQuest(Character chr, int id, int npcid) {
|
||||||
try {
|
try {
|
||||||
Quest.getInstance(id).forceStart(chr, npcid);
|
Quest.getInstance(id).forceStart(chr, npcid);
|
||||||
@@ -859,63 +892,65 @@ public class EventManager {
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTransportationTime(int travelTime) {
|
public int getTransportationTime(int travelTime) {
|
||||||
return this.getWorldServer().getTransportationTime(travelTime);
|
return this.getWorldServer().getTransportationTime(travelTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillEimQueue() {
|
private void fillEimQueue() {
|
||||||
ThreadManager.getInstance().newTask(new EventManagerTask()); //call new thread to fill up readied instances queue
|
ThreadManager.getInstance().newTask(new EventManagerTask()); //call new thread to fill up readied instances queue
|
||||||
}
|
}
|
||||||
|
|
||||||
private EventInstanceManager getReadyInstance() {
|
private EventInstanceManager getReadyInstance() {
|
||||||
queueLock.lock();
|
queueLock.lock();
|
||||||
try {
|
try {
|
||||||
if(readyInstances.isEmpty()) {
|
if (readyInstances.isEmpty()) {
|
||||||
fillEimQueue();
|
fillEimQueue();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
EventInstanceManager eim = readyInstances.remove(0);
|
EventInstanceManager eim = readyInstances.remove(0);
|
||||||
fillEimQueue();
|
fillEimQueue();
|
||||||
|
|
||||||
return eim;
|
return eim;
|
||||||
} finally {
|
} finally {
|
||||||
queueLock.unlock();
|
queueLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void instantiateQueuedInstance() {
|
private void instantiateQueuedInstance() {
|
||||||
int nextEventId;
|
int nextEventId;
|
||||||
queueLock.lock();
|
queueLock.lock();
|
||||||
try {
|
try {
|
||||||
if (this.isDisposed() || readyInstances.size() + onLoadInstances >= Math.ceil((double)maxLobbys / 3.0)) return;
|
if (this.isDisposed() || readyInstances.size() + onLoadInstances >= Math.ceil((double) maxLobbys / 3.0)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
onLoadInstances++;
|
onLoadInstances++;
|
||||||
nextEventId = readyId;
|
nextEventId = readyId;
|
||||||
readyId++;
|
readyId++;
|
||||||
} finally {
|
} finally {
|
||||||
queueLock.unlock();
|
queueLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
EventInstanceManager eim = new EventInstanceManager(this, "sampleName" + nextEventId);
|
EventInstanceManager eim = new EventInstanceManager(this, "sampleName" + nextEventId);
|
||||||
queueLock.lock();
|
queueLock.lock();
|
||||||
try {
|
try {
|
||||||
if (this.isDisposed()) { // EM already disposed
|
if (this.isDisposed()) { // EM already disposed
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
readyInstances.add(eim);
|
readyInstances.add(eim);
|
||||||
onLoadInstances--;
|
onLoadInstances--;
|
||||||
} finally {
|
} finally {
|
||||||
queueLock.unlock();
|
queueLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
instantiateQueuedInstance(); // keep filling the queue until reach threshold.
|
instantiateQueuedInstance(); // keep filling the queue until reach threshold.
|
||||||
}
|
}
|
||||||
|
|
||||||
private class EventManagerTask implements Runnable {
|
private class EventManagerTask implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
instantiateQueuedInstance();
|
instantiateQueuedInstance();
|
||||||
|
|||||||
@@ -22,18 +22,17 @@ package scripting.event;
|
|||||||
import scripting.event.scheduler.EventScriptScheduler;
|
import scripting.event.scheduler.EventScriptScheduler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Ronan
|
* @author Ronan
|
||||||
*/
|
*/
|
||||||
public class EventScheduledFuture {
|
public class EventScheduledFuture {
|
||||||
Runnable r;
|
Runnable r;
|
||||||
EventScriptScheduler ess;
|
EventScriptScheduler ess;
|
||||||
|
|
||||||
public EventScheduledFuture(Runnable r, EventScriptScheduler ess) {
|
public EventScheduledFuture(Runnable r, EventScriptScheduler ess) {
|
||||||
this.r = r;
|
this.r = r;
|
||||||
this.ess = ess;
|
this.ess = ess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancel(boolean dummy) { // will always implement "non-interrupt if running" regardless of boolean value
|
public void cancel(boolean dummy) { // will always implement "non-interrupt if running" regardless of boolean value
|
||||||
ess.cancelEntry(r);
|
ess.cancelEntry(r);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ import java.util.logging.Level;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Matze
|
* @author Matze
|
||||||
*/
|
*/
|
||||||
public class EventScriptManager extends AbstractScriptManager {
|
public class EventScriptManager extends AbstractScriptManager {
|
||||||
@@ -51,6 +50,7 @@ public class EventScriptManager extends AbstractScriptManager {
|
|||||||
this.iv = iv;
|
this.iv = iv;
|
||||||
this.em = em;
|
this.em = em;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Invocable iv;
|
public Invocable iv;
|
||||||
public EventManager em;
|
public EventManager em;
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ public class EventScriptManager extends AbstractScriptManager {
|
|||||||
events.put(script, initializeEventEntry(script, channel));
|
events.put(script, initializeEventEntry(script, channel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
init();
|
init();
|
||||||
fallback = events.remove("0_EXAMPLE");
|
fallback = events.remove("0_EXAMPLE");
|
||||||
}
|
}
|
||||||
@@ -73,11 +73,11 @@ public class EventScriptManager extends AbstractScriptManager {
|
|||||||
}
|
}
|
||||||
return entry.em;
|
return entry.em;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return active;
|
return active;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void init() {
|
public final void init() {
|
||||||
for (EventEntry entry : events.values()) {
|
for (EventEntry entry : events.values()) {
|
||||||
try {
|
try {
|
||||||
@@ -87,7 +87,7 @@ public class EventScriptManager extends AbstractScriptManager {
|
|||||||
System.out.println("Error on script: " + entry.em.getName());
|
System.out.println("Error on script: " + entry.em.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
active = events.size() > 1; // bootup loads only 1 script
|
active = events.size() > 1; // bootup loads only 1 script
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,15 +125,15 @@ public class EventScriptManager extends AbstractScriptManager {
|
|||||||
entry.em.cancel();
|
entry.em.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
if (events.isEmpty()) {
|
if (events.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<EventEntry> eventEntries = new HashSet<>(events.values());
|
Set<EventEntry> eventEntries = new HashSet<>(events.values());
|
||||||
events.clear();
|
events.clear();
|
||||||
|
|
||||||
active = false;
|
active = false;
|
||||||
for (EventEntry entry : eventEntries) {
|
for (EventEntry entry : eventEntries) {
|
||||||
entry.em.cancel();
|
entry.em.cancel();
|
||||||
|
|||||||
@@ -36,18 +36,17 @@ import java.util.Map.Entry;
|
|||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Ronan
|
* @author Ronan
|
||||||
*/
|
*/
|
||||||
public class EventScriptScheduler {
|
public class EventScriptScheduler {
|
||||||
|
|
||||||
private boolean disposed = false;
|
private boolean disposed = false;
|
||||||
private int idleProcs = 0;
|
private int idleProcs = 0;
|
||||||
private Map<Runnable, Long> registeredEntries = new HashMap<>();
|
private final Map<Runnable, Long> registeredEntries = new HashMap<>();
|
||||||
|
|
||||||
private ScheduledFuture<?> schedulerTask = null;
|
private ScheduledFuture<?> schedulerTask = null;
|
||||||
private MonitoredReentrantLock schedulerLock;
|
private MonitoredReentrantLock schedulerLock;
|
||||||
private Runnable monitorTask = () -> runBaseSchedule();
|
private final Runnable monitorTask = () -> runBaseSchedule();
|
||||||
|
|
||||||
public EventScriptScheduler() {
|
public EventScriptScheduler() {
|
||||||
schedulerLock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.EM_SCHDL, true);
|
schedulerLock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.EM_SCHDL, true);
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ import server.ItemInformationProvider.ScriptedItem;
|
|||||||
|
|
||||||
public class ItemScriptManager {
|
public class ItemScriptManager {
|
||||||
|
|
||||||
private static ItemScriptManager instance = new ItemScriptManager();
|
private static final ItemScriptManager instance = new ItemScriptManager();
|
||||||
|
|
||||||
public static ItemScriptManager getInstance() {
|
public static ItemScriptManager getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runItemScript(Client c, ScriptedItem scriptItem) {
|
public void runItemScript(Client c, ScriptedItem scriptItem) {
|
||||||
NPCScriptManager.getInstance().start(c, scriptItem, null);
|
NPCScriptManager.getInstance().start(c, scriptItem, null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,11 +25,10 @@ import client.Client;
|
|||||||
import scripting.AbstractPlayerInteraction;
|
import scripting.AbstractPlayerInteraction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author kevintjuh93
|
* @author kevintjuh93
|
||||||
*/
|
*/
|
||||||
public class ItemScriptMethods extends AbstractPlayerInteraction {
|
public class ItemScriptMethods extends AbstractPlayerInteraction {
|
||||||
public ItemScriptMethods(Client c) {
|
public ItemScriptMethods(Client c) {
|
||||||
super(c);
|
super(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class MapScriptManager extends AbstractScriptManager {
|
|||||||
chr.enteredScript(mapScriptPath, mapid);
|
chr.enteredScript(mapScriptPath, mapid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Invocable iv = scripts.get(mapScriptPath);
|
Invocable iv = scripts.get(mapScriptPath);
|
||||||
if (iv != null) {
|
if (iv != null) {
|
||||||
try {
|
try {
|
||||||
@@ -64,13 +64,13 @@ public class MapScriptManager extends AbstractScriptManager {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
iv = (Invocable) getInvocableScriptEngine("map/" + mapScriptPath + ".js");
|
iv = (Invocable) getInvocableScriptEngine("map/" + mapScriptPath + ".js");
|
||||||
if (iv == null) {
|
if (iv == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
scripts.put(mapScriptPath, iv);
|
scripts.put(mapScriptPath, iv);
|
||||||
iv.invokeFunction("start", new MapScriptMethods(c));
|
iv.invokeFunction("start", new MapScriptMethods(c));
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -29,13 +29,13 @@ import server.quest.Quest;
|
|||||||
import tools.PacketCreator;
|
import tools.PacketCreator;
|
||||||
|
|
||||||
public class MapScriptMethods extends AbstractPlayerInteraction {
|
public class MapScriptMethods extends AbstractPlayerInteraction {
|
||||||
|
|
||||||
private String rewardstring = " title has been rewarded. Please see NPC Dalair to receive your Medal.";
|
private final String rewardstring = " title has been rewarded. Please see NPC Dalair to receive your Medal.";
|
||||||
|
|
||||||
public MapScriptMethods(Client c) {
|
public MapScriptMethods(Client c) {
|
||||||
super(c);
|
super(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayCygnusIntro() {
|
public void displayCygnusIntro() {
|
||||||
switch (c.getPlayer().getMapId()) {
|
switch (c.getPlayer().getMapId()) {
|
||||||
case 913040100:
|
case 913040100:
|
||||||
@@ -63,7 +63,7 @@ public class MapScriptMethods extends AbstractPlayerInteraction {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayAranIntro() {
|
public void displayAranIntro() {
|
||||||
switch (c.getPlayer().getMapId()) {
|
switch (c.getPlayer().getMapId()) {
|
||||||
case 914090010:
|
case 914090010:
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -37,7 +37,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Matze
|
* @author Matze
|
||||||
*/
|
*/
|
||||||
public class NPCScriptManager extends AbstractScriptManager {
|
public class NPCScriptManager extends AbstractScriptManager {
|
||||||
@@ -190,7 +189,7 @@ public class NPCScriptManager extends AbstractScriptManager {
|
|||||||
} else {
|
} else {
|
||||||
resetContext(scriptFolder + "/" + cm.getNpc() + ".js", c);
|
resetContext(scriptFolder + "/" + cm.getNpc() + ".js", c);
|
||||||
}
|
}
|
||||||
|
|
||||||
c.getPlayer().flushDelayedUpdateQuests();
|
c.getPlayer().flushDelayedUpdateQuests();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class PortalScriptManager extends AbstractScriptManager {
|
|||||||
if (script != null) {
|
if (script != null) {
|
||||||
return script;
|
return script;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptEngine engine = getInvocableScriptEngine(scriptPath);
|
ScriptEngine engine = getInvocableScriptEngine(scriptPath);
|
||||||
if (!(engine instanceof Invocable iv)) {
|
if (!(engine instanceof Invocable iv)) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -29,12 +29,11 @@ import server.quest.actions.ExpAction;
|
|||||||
import server.quest.actions.MesoAction;
|
import server.quest.actions.MesoAction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author RMZero213
|
* @author RMZero213
|
||||||
*/
|
*/
|
||||||
public class QuestActionManager extends NPCConversationManager {
|
public class QuestActionManager extends NPCConversationManager {
|
||||||
private boolean start; // this is if the script in question is start or end
|
private final boolean start; // this is if the script in question is start or end
|
||||||
private int quest;
|
private final int quest;
|
||||||
|
|
||||||
public QuestActionManager(Client c, int quest, int npc, boolean start) {
|
public QuestActionManager(Client c, int quest, int npc, boolean start) {
|
||||||
super(c, npc, null);
|
super(c, npc, null);
|
||||||
@@ -62,27 +61,27 @@ public class QuestActionManager extends NPCConversationManager {
|
|||||||
public boolean forceCompleteQuest() {
|
public boolean forceCompleteQuest() {
|
||||||
return forceCompleteQuest(quest);
|
return forceCompleteQuest(quest);
|
||||||
}
|
}
|
||||||
|
|
||||||
// For compatibility with some older scripts...
|
// For compatibility with some older scripts...
|
||||||
public void startQuest() {
|
public void startQuest() {
|
||||||
forceStartQuest();
|
forceStartQuest();
|
||||||
}
|
}
|
||||||
|
|
||||||
// For compatibility with some older scripts...
|
// For compatibility with some older scripts...
|
||||||
public void completeQuest() {
|
public void completeQuest() {
|
||||||
forceCompleteQuest();
|
forceCompleteQuest();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void gainExp(int gain) {
|
public void gainExp(int gain) {
|
||||||
ExpAction.runAction(getPlayer(), gain);
|
ExpAction.runAction(getPlayer(), gain);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void gainMeso(int gain) {
|
public void gainMeso(int gain) {
|
||||||
MesoAction.runAction(getPlayer(), gain);
|
MesoAction.runAction(getPlayer(), gain);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMedalName() { // usable only for medal quests (id 299XX)
|
public String getMedalName() { // usable only for medal quests (id 299XX)
|
||||||
Quest q = Quest.getInstance(quest);
|
Quest q = Quest.getInstance(quest);
|
||||||
return ItemInformationProvider.getInstance().getName(q.getMedalRequirement());
|
return ItemInformationProvider.getInstance().getName(q.getMedalRequirement());
|
||||||
|
|||||||
@@ -35,14 +35,13 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author RMZero213
|
* @author RMZero213
|
||||||
*/
|
*/
|
||||||
public class QuestScriptManager extends AbstractScriptManager {
|
public class QuestScriptManager extends AbstractScriptManager {
|
||||||
private static final QuestScriptManager instance = new QuestScriptManager();
|
private static final QuestScriptManager instance = new QuestScriptManager();
|
||||||
|
|
||||||
private final Map<Client, QuestActionManager> qms = new HashMap<>();
|
private final Map<Client, QuestActionManager> qms = new HashMap<>();
|
||||||
private final Map<Client, Invocable> scripts = new HashMap<>();
|
private final Map<Client, Invocable> scripts = new HashMap<>();
|
||||||
|
|
||||||
public static QuestScriptManager getInstance() {
|
public static QuestScriptManager getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
@@ -56,8 +55,8 @@ public class QuestScriptManager extends AbstractScriptManager {
|
|||||||
|
|
||||||
return engine;
|
return engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start(Client c, short questid, int npc) {
|
public void start(Client c, short questid, int npc) {
|
||||||
Quest quest = Quest.getInstance(questid);
|
Quest quest = Quest.getInstance(questid);
|
||||||
try {
|
try {
|
||||||
QuestActionManager qm = new QuestActionManager(c, questid, npc, true);
|
QuestActionManager qm = new QuestActionManager(c, questid, npc, true);
|
||||||
@@ -95,20 +94,20 @@ public class QuestScriptManager extends AbstractScriptManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start(Client c, byte mode, byte type, int selection) {
|
public void start(Client c, byte mode, byte type, int selection) {
|
||||||
Invocable iv = scripts.get(c);
|
Invocable iv = scripts.get(c);
|
||||||
if (iv != null) {
|
if (iv != null) {
|
||||||
try {
|
try {
|
||||||
c.setClickedNPC();
|
c.setClickedNPC();
|
||||||
iv.invokeFunction("start", mode, type, selection);
|
iv.invokeFunction("start", mode, type, selection);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", e);
|
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", e);
|
||||||
dispose(c);
|
dispose(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void end(Client c, short questid, int npc) {
|
public void end(Client c, short questid, int npc) {
|
||||||
Quest quest = Quest.getInstance(questid);
|
Quest quest = Quest.getInstance(questid);
|
||||||
if (!c.getPlayer().getQuest(quest).getStatus().equals(QuestStatus.Status.STARTED) || !c.getPlayer().getMap().containsNPC(npc)) {
|
if (!c.getPlayer().getQuest(quest).getStatus().equals(QuestStatus.Status.STARTED) || !c.getPlayer().getMap().containsNPC(npc)) {
|
||||||
dispose(c);
|
dispose(c);
|
||||||
@@ -150,50 +149,50 @@ public class QuestScriptManager extends AbstractScriptManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void end(Client c, byte mode, byte type, int selection) {
|
public void end(Client c, byte mode, byte type, int selection) {
|
||||||
Invocable iv = scripts.get(c);
|
Invocable iv = scripts.get(c);
|
||||||
if (iv != null) {
|
if (iv != null) {
|
||||||
try {
|
|
||||||
c.setClickedNPC();
|
|
||||||
iv.invokeFunction("end", mode, type, selection);
|
|
||||||
} catch (final Exception e) {
|
|
||||||
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", e);
|
|
||||||
dispose(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void raiseOpen(Client c, short questid, int npc) {
|
|
||||||
try {
|
try {
|
||||||
QuestActionManager qm = new QuestActionManager(c, questid, npc, true);
|
c.setClickedNPC();
|
||||||
if (qms.containsKey(c)) {
|
iv.invokeFunction("end", mode, type, selection);
|
||||||
return;
|
} catch (final Exception e) {
|
||||||
}
|
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", e);
|
||||||
if (c.canClickNPC()) {
|
|
||||||
qms.put(c, qm);
|
|
||||||
|
|
||||||
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);
|
dispose(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void raiseOpen(Client 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);
|
||||||
|
|
||||||
|
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, Client c) {
|
public void dispose(QuestActionManager qm, Client c) {
|
||||||
qms.remove(c);
|
qms.remove(c);
|
||||||
@@ -203,12 +202,12 @@ public class QuestScriptManager extends AbstractScriptManager {
|
|||||||
c.getPlayer().flushDelayedUpdateQuests();
|
c.getPlayer().flushDelayedUpdateQuests();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispose(Client c) {
|
public void dispose(Client c) {
|
||||||
QuestActionManager qm = qms.get(c);
|
QuestActionManager qm = qms.get(c);
|
||||||
if (qm != null) {
|
if (qm != null) {
|
||||||
dispose(qm, c);
|
dispose(qm, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public QuestActionManager getQM(Client c) {
|
public QuestActionManager getQM(Client c) {
|
||||||
return qms.get(c);
|
return qms.get(c);
|
||||||
|
|||||||
@@ -66,19 +66,19 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
|
|||||||
public void hitReactor() {
|
public void hitReactor() {
|
||||||
reactor.hitReactor(c);
|
reactor.hitReactor(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroyNpc(int npcId) {
|
public void destroyNpc(int npcId) {
|
||||||
reactor.getMap().destroyNPC(npcId);
|
reactor.getMap().destroyNPC(npcId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sortDropEntries(List<ReactorDropEntry> from, List<ReactorDropEntry> item, List<ReactorDropEntry> visibleQuest, List<ReactorDropEntry> otherQuest, Character chr) {
|
private static void sortDropEntries(List<ReactorDropEntry> from, List<ReactorDropEntry> item, List<ReactorDropEntry> visibleQuest, List<ReactorDropEntry> otherQuest, Character chr) {
|
||||||
ItemInformationProvider ii = ItemInformationProvider.getInstance();
|
ItemInformationProvider ii = ItemInformationProvider.getInstance();
|
||||||
|
|
||||||
for(ReactorDropEntry mde : from) {
|
for (ReactorDropEntry mde : from) {
|
||||||
if(!ii.isQuestItem(mde.itemId)) {
|
if (!ii.isQuestItem(mde.itemId)) {
|
||||||
item.add(mde);
|
item.add(mde);
|
||||||
} else {
|
} else {
|
||||||
if(chr.needQuestItem(mde.questid, mde.itemId)) {
|
if (chr.needQuestItem(mde.questid, mde.itemId)) {
|
||||||
visibleQuest.add(mde);
|
visibleQuest.add(mde);
|
||||||
} else {
|
} else {
|
||||||
otherQuest.add(mde);
|
otherQuest.add(mde);
|
||||||
@@ -86,25 +86,25 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<ReactorDropEntry> assembleReactorDropEntries(Character chr, List<ReactorDropEntry> items) {
|
private static List<ReactorDropEntry> assembleReactorDropEntries(Character chr, List<ReactorDropEntry> items) {
|
||||||
final List<ReactorDropEntry> dropEntry = new ArrayList<>();
|
final List<ReactorDropEntry> dropEntry = new ArrayList<>();
|
||||||
final List<ReactorDropEntry> visibleQuestEntry = new ArrayList<>();
|
final List<ReactorDropEntry> visibleQuestEntry = new ArrayList<>();
|
||||||
final List<ReactorDropEntry> otherQuestEntry = new ArrayList<>();
|
final List<ReactorDropEntry> otherQuestEntry = new ArrayList<>();
|
||||||
sortDropEntries(items, dropEntry, visibleQuestEntry, otherQuestEntry, chr);
|
sortDropEntries(items, dropEntry, visibleQuestEntry, otherQuestEntry, chr);
|
||||||
|
|
||||||
Collections.shuffle(dropEntry);
|
Collections.shuffle(dropEntry);
|
||||||
Collections.shuffle(visibleQuestEntry);
|
Collections.shuffle(visibleQuestEntry);
|
||||||
Collections.shuffle(otherQuestEntry);
|
Collections.shuffle(otherQuestEntry);
|
||||||
|
|
||||||
items.clear();
|
items.clear();
|
||||||
items.addAll(dropEntry);
|
items.addAll(dropEntry);
|
||||||
items.addAll(visibleQuestEntry);
|
items.addAll(visibleQuestEntry);
|
||||||
items.addAll(otherQuestEntry);
|
items.addAll(otherQuestEntry);
|
||||||
|
|
||||||
List<ReactorDropEntry> items1 = new ArrayList<>(items.size());
|
List<ReactorDropEntry> items1 = new ArrayList<>(items.size());
|
||||||
List<ReactorDropEntry> items2 = new ArrayList<>(items.size() / 2);
|
List<ReactorDropEntry> items2 = new ArrayList<>(items.size() / 2);
|
||||||
|
|
||||||
for (int i = 0; i < items.size(); i++) {
|
for (int i = 0; i < items.size(); i++) {
|
||||||
if (i % 2 == 0) {
|
if (i % 2 == 0) {
|
||||||
items1.add(items.get(i));
|
items1.add(items.get(i));
|
||||||
@@ -112,10 +112,10 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
|
|||||||
items2.add(items.get(i));
|
items2.add(items.get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.reverse(items1);
|
Collections.reverse(items1);
|
||||||
items1.addAll(items2);
|
items1.addAll(items2);
|
||||||
|
|
||||||
return items1;
|
return items1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,15 +126,15 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
|
|||||||
public void sprayItems(boolean meso, int mesoChance, int minMeso, int maxMeso) {
|
public void sprayItems(boolean meso, int mesoChance, int minMeso, int maxMeso) {
|
||||||
sprayItems(meso, mesoChance, minMeso, maxMeso, 0);
|
sprayItems(meso, mesoChance, minMeso, maxMeso, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sprayItems(boolean meso, int mesoChance, int minMeso, int maxMeso, int minItems) {
|
public void sprayItems(boolean meso, int mesoChance, int minMeso, int maxMeso, int minItems) {
|
||||||
sprayItems((int)reactor.getPosition().getX(), (int)reactor.getPosition().getY(), meso, mesoChance, minMeso, maxMeso, minItems);
|
sprayItems((int) reactor.getPosition().getX(), (int) reactor.getPosition().getY(), meso, mesoChance, minMeso, maxMeso, minItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sprayItems(int posX, int posY, boolean meso, int mesoChance, int minMeso, int maxMeso, int minItems) {
|
public void sprayItems(int posX, int posY, boolean meso, int mesoChance, int minMeso, int maxMeso, int minItems) {
|
||||||
dropItems(true, posX, posY, meso, mesoChance, minMeso, maxMeso, minItems);
|
dropItems(true, posX, posY, meso, mesoChance, minMeso, maxMeso, minItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dropItems() {
|
public void dropItems() {
|
||||||
dropItems(false, 0, 0, 0, 0);
|
dropItems(false, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
@@ -142,31 +142,35 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
|
|||||||
public void dropItems(boolean meso, int mesoChance, int minMeso, int maxMeso) {
|
public void dropItems(boolean meso, int mesoChance, int minMeso, int maxMeso) {
|
||||||
dropItems(meso, mesoChance, minMeso, maxMeso, 0);
|
dropItems(meso, mesoChance, minMeso, maxMeso, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dropItems(boolean meso, int mesoChance, int minMeso, int maxMeso, int minItems) {
|
public void dropItems(boolean meso, int mesoChance, int minMeso, int maxMeso, int minItems) {
|
||||||
dropItems((int)reactor.getPosition().getX(), (int)reactor.getPosition().getY(), meso, mesoChance, minMeso, maxMeso, minItems);
|
dropItems((int) reactor.getPosition().getX(), (int) reactor.getPosition().getY(), meso, mesoChance, minMeso, maxMeso, minItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dropItems(int posX, int posY, boolean meso, int mesoChance, int minMeso, int maxMeso, int minItems) {
|
public void dropItems(int posX, int posY, boolean meso, int mesoChance, int minMeso, int maxMeso, int minItems) {
|
||||||
dropItems(true, posX, posY, meso, mesoChance, minMeso, maxMeso, minItems); // all reactors actually drop items sequentially... thanks inhyuk for pointing this out!
|
dropItems(true, posX, posY, meso, mesoChance, minMeso, maxMeso, minItems); // all reactors actually drop items sequentially... thanks inhyuk for pointing this out!
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dropItems(boolean delayed, int posX, int posY, boolean meso, int mesoChance, final int minMeso, final int maxMeso, int minItems) {
|
public void dropItems(boolean delayed, int posX, int posY, boolean meso, int mesoChance, final int minMeso, final int maxMeso, int minItems) {
|
||||||
Character chr = c.getPlayer();
|
Character chr = c.getPlayer();
|
||||||
if(chr == null) return;
|
if (chr == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
List<ReactorDropEntry> items = assembleReactorDropEntries(chr, generateDropList(getDropChances(), chr.getDropRate(), meso, mesoChance, minItems));
|
List<ReactorDropEntry> items = assembleReactorDropEntries(chr, generateDropList(getDropChances(), chr.getDropRate(), meso, mesoChance, minItems));
|
||||||
if(items.size() % 2 == 0) posX -= 12;
|
if (items.size() % 2 == 0) {
|
||||||
|
posX -= 12;
|
||||||
|
}
|
||||||
final Point dropPos = new Point(posX, posY);
|
final Point dropPos = new Point(posX, posY);
|
||||||
|
|
||||||
if(!delayed) {
|
if (!delayed) {
|
||||||
ItemInformationProvider ii = ItemInformationProvider.getInstance();
|
ItemInformationProvider ii = ItemInformationProvider.getInstance();
|
||||||
|
|
||||||
byte p = 1;
|
byte p = 1;
|
||||||
for (ReactorDropEntry d : items) {
|
for (ReactorDropEntry d : items) {
|
||||||
dropPos.x = posX + ((p % 2 == 0) ? (25 * ((p + 1) / 2)) : -(25 * (p / 2)));
|
dropPos.x = posX + ((p % 2 == 0) ? (25 * ((p + 1) / 2)) : -(25 * (p / 2)));
|
||||||
p++;
|
p++;
|
||||||
|
|
||||||
if (d.itemId == 0) {
|
if (d.itemId == 0) {
|
||||||
int range = maxMeso - minMeso;
|
int range = maxMeso - minMeso;
|
||||||
int displayDrop = (int) (Math.random() * range) + minMeso;
|
int displayDrop = (int) (Math.random() * range) + minMeso;
|
||||||
@@ -174,7 +178,7 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
|
|||||||
reactor.getMap().spawnMesoDrop(mesoDrop, reactor.getMap().calcDropPos(dropPos, reactor.getPosition()), reactor, c.getPlayer(), false, (byte) 2);
|
reactor.getMap().spawnMesoDrop(mesoDrop, reactor.getMap().calcDropPos(dropPos, reactor.getPosition()), reactor, c.getPlayer(), false, (byte) 2);
|
||||||
} else {
|
} else {
|
||||||
Item drop;
|
Item drop;
|
||||||
|
|
||||||
if (ItemConstants.getInventoryType(d.itemId) != InventoryType.EQUIP) {
|
if (ItemConstants.getInventoryType(d.itemId) != InventoryType.EQUIP) {
|
||||||
drop = new Item(d.itemId, (short) 0, (short) 1);
|
drop = new Item(d.itemId, (short) 0, (short) 1);
|
||||||
} else {
|
} else {
|
||||||
@@ -188,11 +192,11 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
|
|||||||
final Reactor r = reactor;
|
final Reactor r = reactor;
|
||||||
final List<ReactorDropEntry> dropItems = items;
|
final List<ReactorDropEntry> dropItems = items;
|
||||||
final int worldMesoRate = c.getWorldServer().getMesoRate();
|
final int worldMesoRate = c.getWorldServer().getMesoRate();
|
||||||
|
|
||||||
dropPos.x -= (12 * items.size());
|
dropPos.x -= (12 * items.size());
|
||||||
|
|
||||||
sprayTask = TimerManager.getInstance().register(() -> {
|
sprayTask = TimerManager.getInstance().register(() -> {
|
||||||
if(dropItems.isEmpty()) {
|
if (dropItems.isEmpty()) {
|
||||||
sprayTask.cancel(false);
|
sprayTask.cancel(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -224,23 +228,23 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
|
|||||||
private List<ReactorDropEntry> getDropChances() {
|
private List<ReactorDropEntry> getDropChances() {
|
||||||
return ReactorScriptManager.getInstance().getDrops(reactor.getId());
|
return ReactorScriptManager.getInstance().getDrops(reactor.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ReactorDropEntry> generateDropList(List<ReactorDropEntry> drops, int dropRate, boolean meso, int mesoChance, int minItems) {
|
private List<ReactorDropEntry> generateDropList(List<ReactorDropEntry> drops, int dropRate, boolean meso, int mesoChance, int minItems) {
|
||||||
List<ReactorDropEntry> items = new ArrayList<>();
|
List<ReactorDropEntry> items = new ArrayList<>();
|
||||||
if (meso && Math.random() < (1 / (double) mesoChance)) {
|
if (meso && Math.random() < (1 / (double) mesoChance)) {
|
||||||
items.add(new ReactorDropEntry(0, mesoChance, -1));
|
items.add(new ReactorDropEntry(0, mesoChance, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
for(ReactorDropEntry mde : drops) {
|
for (ReactorDropEntry mde : drops) {
|
||||||
if (Math.random() < (dropRate / (double) mde.chance)) {
|
if (Math.random() < (dropRate / (double) mde.chance)) {
|
||||||
items.add(mde);
|
items.add(mde);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (items.size() < minItems) {
|
while (items.size() < minItems) {
|
||||||
items.add(new ReactorDropEntry(0, mesoChance, -1));
|
items.add(new ReactorDropEntry(0, mesoChance, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,28 +275,28 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
|
|||||||
pos.y -= 10;
|
pos.y -= 10;
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void spawnNpc(int npcId) {
|
public void spawnNpc(int npcId) {
|
||||||
spawnNpc(npcId, getPosition());
|
spawnNpc(npcId, getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void spawnNpc(int npcId, Point pos) {
|
public void spawnNpc(int npcId, Point pos) {
|
||||||
spawnNpc(npcId, pos, reactor.getMap());
|
spawnNpc(npcId, pos, reactor.getMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hitMonsterWithReactor(int id, int hitsToKill) { // until someone comes with a better solution, why not?
|
public void hitMonsterWithReactor(int id, int hitsToKill) { // until someone comes with a better solution, why not?
|
||||||
int customTime = YamlConfig.config.server.MOB_REACTOR_REFRESH_TIME;
|
int customTime = YamlConfig.config.server.MOB_REACTOR_REFRESH_TIME;
|
||||||
if(customTime > 0) {
|
if (customTime > 0) {
|
||||||
reactor.setDelay(customTime);
|
reactor.setDelay(customTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
MapleMap map = reactor.getMap();
|
MapleMap map = reactor.getMap();
|
||||||
Monster mm = map.getMonsterById(id);
|
Monster mm = map.getMonsterById(id);
|
||||||
if(mm != null) {
|
if (mm != null) {
|
||||||
int damage = (int)Math.ceil(mm.getMaxHp() / hitsToKill);
|
int damage = (int) Math.ceil(mm.getMaxHp() / hitsToKill);
|
||||||
Character chr = this.getPlayer();
|
Character chr = this.getPlayer();
|
||||||
|
|
||||||
if(chr != null) {
|
if (chr != null) {
|
||||||
map.damageMonster(chr, mm, damage);
|
map.damageMonster(chr, mm, damage);
|
||||||
map.broadcastMessage(PacketCreator.damageMonster(mm.getObjectId(), damage));
|
map.broadcastMessage(PacketCreator.damageMonster(mm.getObjectId(), damage));
|
||||||
}
|
}
|
||||||
@@ -322,12 +326,12 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
|
|||||||
changeMusic(bgmName);
|
changeMusic(bgmName);
|
||||||
mapMessage(6, summonMessage);
|
mapMessage(6, summonMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dispelAllMonsters(int num, int team) { //dispels all mobs, cpq
|
public void dispelAllMonsters(int num, int team) { //dispels all mobs, cpq
|
||||||
final MCSkill skil = CarnivalFactory.getInstance().getGuardian(num);
|
final MCSkill skil = CarnivalFactory.getInstance().getGuardian(num);
|
||||||
if (skil != null) {
|
if (skil != null) {
|
||||||
for (Monster mons : getMap().getAllMonsters()) {
|
for (Monster mons : getMap().getAllMonsters()) {
|
||||||
if(mons.getTeam() == team) {
|
if (mons.getTeam() == team) {
|
||||||
mons.dispelSkill(skil.getSkill());
|
mons.dispelSkill(skil.getSkill());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,13 +44,13 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class ReactorScriptManager extends AbstractScriptManager {
|
public class ReactorScriptManager extends AbstractScriptManager {
|
||||||
private static final ReactorScriptManager instance = new ReactorScriptManager();
|
private static final ReactorScriptManager instance = new ReactorScriptManager();
|
||||||
|
|
||||||
private final Map<Integer, List<ReactorDropEntry>> drops = new HashMap<>();
|
private final Map<Integer, List<ReactorDropEntry>> drops = new HashMap<>();
|
||||||
|
|
||||||
public static ReactorScriptManager getInstance() {
|
public static ReactorScriptManager getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onHit(Client c, Reactor reactor) {
|
public void onHit(Client c, Reactor reactor) {
|
||||||
try {
|
try {
|
||||||
Invocable iv = initializeInvocable(c, reactor);
|
Invocable iv = initializeInvocable(c, reactor);
|
||||||
@@ -59,9 +59,10 @@ public class ReactorScriptManager extends AbstractScriptManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
iv.invokeFunction("hit");
|
iv.invokeFunction("hit");
|
||||||
} catch (final NoSuchMethodException e) {} //do nothing, hit is OPTIONAL
|
} catch (final NoSuchMethodException e) {
|
||||||
|
} //do nothing, hit is OPTIONAL
|
||||||
catch (final ScriptException | NullPointerException e) {
|
|
||||||
|
catch (final ScriptException | NullPointerException e) {
|
||||||
FilePrinter.printError(FilePrinter.REACTOR + reactor.getId() + ".txt", e);
|
FilePrinter.printError(FilePrinter.REACTOR + reactor.getId() + ".txt", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user