Reformat and clean up "scripting" package
This commit is contained in:
@@ -32,7 +32,6 @@ import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Matze
|
||||
*/
|
||||
public abstract class AbstractScriptManager {
|
||||
|
||||
@@ -60,29 +60,28 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Matze
|
||||
* @author Ronan
|
||||
*/
|
||||
public class EventInstanceManager {
|
||||
private Map<Integer, Character> chars = new HashMap<>();
|
||||
private final Map<Integer, Character> chars = new HashMap<>();
|
||||
private int leaderId = -1;
|
||||
private List<Monster> mobs = new LinkedList<>();
|
||||
private Map<Character, Integer> killCount = new HashMap<>();
|
||||
private final List<Monster> mobs = new LinkedList<>();
|
||||
private final Map<Character, Integer> killCount = new HashMap<>();
|
||||
private EventManager em;
|
||||
private EventScriptScheduler ess;
|
||||
private MapManager mapManager;
|
||||
private String name;
|
||||
private Properties props = new Properties();
|
||||
private Map<String, Object> objectProps = new HashMap<>();
|
||||
private final Properties props = new Properties();
|
||||
private final Map<String, Object> objectProps = new HashMap<>();
|
||||
private long timeStarted = 0;
|
||||
private long eventTime = 0;
|
||||
private Expedition expedition = null;
|
||||
private List<Integer> mapIds = new LinkedList<>();
|
||||
private final List<Integer> mapIds = new LinkedList<>();
|
||||
|
||||
private final MonitoredReentrantReadWriteLock lock = new MonitoredReentrantReadWriteLock(MonitoredLockType.EIM, true);
|
||||
private MonitoredReadLock rL = MonitoredReadLockFactory.createLock(lock);
|
||||
private MonitoredWriteLock wL = MonitoredWriteLockFactory.createLock(lock);
|
||||
private final MonitoredReadLock rL = MonitoredReadLockFactory.createLock(lock);
|
||||
private final MonitoredWriteLock wL = MonitoredWriteLockFactory.createLock(lock);
|
||||
|
||||
private MonitoredReentrantLock pL = MonitoredReentrantLockFactory.createLock(MonitoredLockType.EIM_PARTY, true);
|
||||
private MonitoredReentrantLock sL = MonitoredReentrantLockFactory.createLock(MonitoredLockType.EIM_SCRIPT, true);
|
||||
@@ -93,22 +92,22 @@ public class EventInstanceManager {
|
||||
private boolean eventStarted = false;
|
||||
|
||||
// multi-leveled PQ rewards!
|
||||
private Map<Integer, List<Integer>> collectionSet = new HashMap<>(YamlConfig.config.server.MAX_EVENT_LEVELS);
|
||||
private Map<Integer, List<Integer>> collectionQty = new HashMap<>(YamlConfig.config.server.MAX_EVENT_LEVELS);
|
||||
private Map<Integer, Integer> collectionExp = new HashMap<>(YamlConfig.config.server.MAX_EVENT_LEVELS);
|
||||
private final Map<Integer, List<Integer>> collectionSet = new HashMap<>(YamlConfig.config.server.MAX_EVENT_LEVELS);
|
||||
private final Map<Integer, List<Integer>> collectionQty = new HashMap<>(YamlConfig.config.server.MAX_EVENT_LEVELS);
|
||||
private final Map<Integer, Integer> collectionExp = new HashMap<>(YamlConfig.config.server.MAX_EVENT_LEVELS);
|
||||
|
||||
// Exp/Meso rewards by CLEAR on a stage
|
||||
private List<Integer> onMapClearExp = new ArrayList<>();
|
||||
private List<Integer> onMapClearMeso = new ArrayList<>();
|
||||
private final List<Integer> onMapClearExp = new ArrayList<>();
|
||||
private final List<Integer> onMapClearMeso = new ArrayList<>();
|
||||
|
||||
// registers player status on an event (null on this Map structure equals to 0)
|
||||
private Map<Integer, Integer> playerGrid = new HashMap<>();
|
||||
private final Map<Integer, Integer> playerGrid = new HashMap<>();
|
||||
|
||||
// registers all opened gates on the event. Will help late characters to encounter next stages gates already opened
|
||||
private Map<Integer, Pair<String, Integer>> openedGates = new HashMap<>();
|
||||
private final Map<Integer, Pair<String, Integer>> openedGates = new HashMap<>();
|
||||
|
||||
// forces deletion of items not supposed to be held outside of the event, dealt on a player's leaving moment.
|
||||
private Set<Integer> exclusiveItems = new HashSet<>();
|
||||
private final Set<Integer> exclusiveItems = new HashSet<>();
|
||||
|
||||
public EventInstanceManager(EventManager em, String name) {
|
||||
this.em = em;
|
||||
@@ -176,7 +175,9 @@ public class EventInstanceManager {
|
||||
}
|
||||
|
||||
public void giveEventPlayersExp(int gain, int mapId) {
|
||||
if(gain == 0) return;
|
||||
if (gain == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Character> players = getPlayerList();
|
||||
|
||||
@@ -184,10 +185,11 @@ public class EventInstanceManager {
|
||||
for (Character mc : players) {
|
||||
mc.gainExp(gain * mc.getExpRate(), true, true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
for (Character mc : players) {
|
||||
if(mc.getMapId() == mapId) mc.gainExp(gain * mc.getExpRate(), true, true);
|
||||
if (mc.getMapId() == mapId) {
|
||||
mc.gainExp(gain * mc.getExpRate(), true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,7 +199,9 @@ public class EventInstanceManager {
|
||||
}
|
||||
|
||||
public void giveEventPlayersMeso(int gain, int mapId) {
|
||||
if(gain == 0) return;
|
||||
if (gain == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Character> players = getPlayerList();
|
||||
|
||||
@@ -205,10 +209,11 @@ public class EventInstanceManager {
|
||||
for (Character mc : players) {
|
||||
mc.gainMeso(gain * mc.getMesoRate());
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
for (Character mc : players) {
|
||||
if(mc.getMapId() == mapId) mc.gainMeso(gain * mc.getMesoRate());
|
||||
if (mc.getMapId() == mapId) {
|
||||
mc.gainMeso(gain * mc.getMesoRate());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,13 +453,15 @@ public class EventInstanceManager {
|
||||
public void changedMap(final Character chr, final int mapId) {
|
||||
try {
|
||||
invokeScriptFunction("changedMap", EventInstanceManager.this, chr, mapId);
|
||||
} catch (ScriptException | NoSuchMethodException ex) {} // optional
|
||||
} catch (ScriptException | NoSuchMethodException ex) {
|
||||
} // optional
|
||||
}
|
||||
|
||||
public void afterChangedMap(final Character chr, final int mapId) {
|
||||
try {
|
||||
invokeScriptFunction("afterChangedMap", EventInstanceManager.this, chr, mapId);
|
||||
} catch (ScriptException | NoSuchMethodException ex) {} // optional
|
||||
} catch (ScriptException | NoSuchMethodException ex) {
|
||||
} // optional
|
||||
}
|
||||
|
||||
public synchronized void changedLeader(final PartyCharacter ldr) {
|
||||
@@ -505,33 +512,38 @@ public class EventInstanceManager {
|
||||
public void friendlyKilled(final Monster mob, final boolean hasKiller) {
|
||||
try {
|
||||
invokeScriptFunction("friendlyKilled", mob, EventInstanceManager.this, hasKiller);
|
||||
} catch (ScriptException | NoSuchMethodException ex) {} //optional
|
||||
} catch (ScriptException | NoSuchMethodException ex) {
|
||||
} //optional
|
||||
}
|
||||
|
||||
public void friendlyDamaged(final Monster mob) {
|
||||
try {
|
||||
invokeScriptFunction("friendlyDamaged", EventInstanceManager.this, mob);
|
||||
} catch (ScriptException | NoSuchMethodException ex) {} // optional
|
||||
} catch (ScriptException | NoSuchMethodException ex) {
|
||||
} // optional
|
||||
}
|
||||
|
||||
public void friendlyItemDrop(final Monster mob) {
|
||||
try {
|
||||
invokeScriptFunction("friendlyItemDrop", EventInstanceManager.this, mob);
|
||||
} catch (ScriptException | NoSuchMethodException ex) {} // optional
|
||||
} catch (ScriptException | NoSuchMethodException ex) {
|
||||
} // optional
|
||||
}
|
||||
|
||||
public void playerKilled(final Character chr) {
|
||||
ThreadManager.getInstance().newTask(() -> {
|
||||
try {
|
||||
invokeScriptFunction("playerDead", EventInstanceManager.this, chr);
|
||||
} catch (ScriptException | NoSuchMethodException ex) {} // optional
|
||||
} catch (ScriptException | NoSuchMethodException ex) {
|
||||
} // optional
|
||||
});
|
||||
}
|
||||
|
||||
public void reviveMonster(final Monster mob) {
|
||||
try {
|
||||
invokeScriptFunction("monsterRevive", EventInstanceManager.this, mob);
|
||||
} catch (ScriptException | NoSuchMethodException ex) {} // optional
|
||||
} catch (ScriptException | NoSuchMethodException ex) {
|
||||
} // optional
|
||||
}
|
||||
|
||||
public boolean revivePlayer(final Character chr) {
|
||||
@@ -540,7 +552,8 @@ public class EventInstanceManager {
|
||||
if (b instanceof Boolean) {
|
||||
return (Boolean) b;
|
||||
}
|
||||
} catch (ScriptException | NoSuchMethodException ex) {} // optional
|
||||
} catch (ScriptException | NoSuchMethodException ex) {
|
||||
} // optional
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -584,7 +597,9 @@ public class EventInstanceManager {
|
||||
public void dispose() {
|
||||
rL.lock();
|
||||
try {
|
||||
for(Character chr: chars.values()) chr.setEventInstance(null);
|
||||
for (Character chr : chars.values()) {
|
||||
chr.setEventInstance(null);
|
||||
}
|
||||
} finally {
|
||||
rL.unlock();
|
||||
}
|
||||
@@ -593,7 +608,9 @@ public class EventInstanceManager {
|
||||
}
|
||||
|
||||
public synchronized void dispose(boolean shutdown) { // should not trigger any event script method after disposed
|
||||
if(disposed) return;
|
||||
if (disposed) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
invokeScriptFunction("dispose", EventInstanceManager.this);
|
||||
@@ -606,7 +623,9 @@ public class EventInstanceManager {
|
||||
|
||||
wL.lock();
|
||||
try {
|
||||
for(Character chr: chars.values()) chr.setEventInstance(null);
|
||||
for (Character chr : chars.values()) {
|
||||
chr.setEventInstance(null);
|
||||
}
|
||||
chars.clear();
|
||||
mobs.clear();
|
||||
ess = null;
|
||||
@@ -628,7 +647,9 @@ public class EventInstanceManager {
|
||||
|
||||
sL.lock();
|
||||
try {
|
||||
if(!eventCleared) em.disposeInstance(name);
|
||||
if (!eventCleared) {
|
||||
em.disposeInstance(name);
|
||||
}
|
||||
} finally {
|
||||
sL.unlock();
|
||||
}
|
||||
@@ -901,12 +922,16 @@ public class EventInstanceManager {
|
||||
}
|
||||
|
||||
public Integer getClearStageExp(int stage) { //stage counts from ONE.
|
||||
if(stage > onMapClearExp.size()) return 0;
|
||||
if (stage > onMapClearExp.size()) {
|
||||
return 0;
|
||||
}
|
||||
return onMapClearExp.get(stage - 1);
|
||||
}
|
||||
|
||||
public Integer getClearStageMeso(int stage) { //stage counts from ONE.
|
||||
if(stage > onMapClearMeso.size()) return 0;
|
||||
if (stage > onMapClearMeso.size()) {
|
||||
return 0;
|
||||
}
|
||||
return onMapClearMeso.get(stage - 1);
|
||||
}
|
||||
|
||||
@@ -952,7 +977,9 @@ public class EventInstanceManager {
|
||||
public final void setEventRewards(int eventLevel, List<Object> rwds, List<Object> qtys, int expGiven) {
|
||||
// fixed EXP will be rewarded at the same time the random item is given
|
||||
|
||||
if(eventLevel <= 0 || eventLevel > YamlConfig.config.server.MAX_EVENT_LEVELS) return;
|
||||
if (eventLevel <= 0 || eventLevel > YamlConfig.config.server.MAX_EVENT_LEVELS) {
|
||||
return;
|
||||
}
|
||||
eventLevel--; //event level starts from 1
|
||||
|
||||
List<Integer> rewardIds = convertToIntegerList(rwds);
|
||||
@@ -970,7 +997,9 @@ public class EventInstanceManager {
|
||||
}
|
||||
|
||||
private byte getRewardListRequirements(int level) {
|
||||
if(level >= collectionSet.size()) return 0;
|
||||
if (level >= collectionSet.size()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
byte rewardTypes = 0;
|
||||
List<Integer> list = collectionSet.get(level);
|
||||
@@ -987,9 +1016,10 @@ public class EventInstanceManager {
|
||||
|
||||
//iterating over all valid inventory types
|
||||
for (byte type = 1; type <= 5; type++) {
|
||||
if((listReq >> type) % 2 == 1 && !player.hasEmptySlot(type))
|
||||
if ((listReq >> type) % 2 == 1 && !player.hasEmptySlot(type)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1006,7 +1036,9 @@ public class EventInstanceManager {
|
||||
rL.lock();
|
||||
try {
|
||||
eventLevel--; //event level starts counting from 1
|
||||
if(eventLevel >= collectionSet.size()) return true;
|
||||
if (eventLevel >= collectionSet.size()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
rewardsSet = collectionSet.get(eventLevel);
|
||||
rewardsQty = collectionQty.get(eventLevel);
|
||||
@@ -1016,20 +1048,28 @@ public class EventInstanceManager {
|
||||
rL.unlock();
|
||||
}
|
||||
|
||||
if(rewardExp == null) rewardExp = 0;
|
||||
if (rewardExp == null) {
|
||||
rewardExp = 0;
|
||||
}
|
||||
|
||||
if (rewardsSet == null || rewardsSet.isEmpty()) {
|
||||
if(rewardExp > 0) player.gainExp(rewardExp);
|
||||
if (rewardExp > 0) {
|
||||
player.gainExp(rewardExp);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!hasRewardSlot(player, eventLevel)) return false;
|
||||
if (!hasRewardSlot(player, eventLevel)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AbstractPlayerInteraction api = player.getAbstractPlayerInteraction();
|
||||
int rnd = (int) Math.floor(Math.random() * rewardsSet.size());
|
||||
|
||||
api.gainItem(rewardsSet.get(rnd), rewardsQty.get(rnd).shortValue());
|
||||
if(rewardExp > 0) player.gainExp(rewardExp);
|
||||
if (rewardExp > 0) {
|
||||
player.gainExp(rewardExp);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1085,47 +1125,51 @@ public class EventInstanceManager {
|
||||
|
||||
private boolean isEventTeamLeaderOn() {
|
||||
for (Character chr : getPlayers()) {
|
||||
if(chr.getId() == getLeaderId()) return true;
|
||||
if (chr.getId() == getLeaderId()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public final boolean checkEventTeamLacking(boolean leavingEventMap, int minPlayers) {
|
||||
if(eventCleared && getPlayerCount() > 1) return false;
|
||||
|
||||
if(!eventCleared && leavingEventMap && !isEventTeamLeaderOn()) return true;
|
||||
if(getPlayerCount() < minPlayers) return true;
|
||||
|
||||
if (eventCleared && getPlayerCount() > 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!eventCleared && leavingEventMap && !isEventTeamLeaderOn()) {
|
||||
return true;
|
||||
}
|
||||
return getPlayerCount() < minPlayers;
|
||||
}
|
||||
|
||||
public final boolean isExpeditionTeamLackingNow(boolean leavingEventMap, int minPlayers, Character quitter) {
|
||||
if (eventCleared) {
|
||||
if(leavingEventMap && getPlayerCount() <= 1) return true;
|
||||
return leavingEventMap && getPlayerCount() <= 1;
|
||||
} else {
|
||||
// thanks Conrad for noticing expeditions don't need to have neither the leader nor meet the minimum requirement inside the event
|
||||
if(getPlayerCount() <= 1) return true;
|
||||
return getPlayerCount() <= 1;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public final boolean isEventTeamLackingNow(boolean leavingEventMap, int minPlayers, Character quitter) {
|
||||
if (eventCleared) {
|
||||
if(leavingEventMap && getPlayerCount() <= 1) return true;
|
||||
return leavingEventMap && getPlayerCount() <= 1;
|
||||
} else {
|
||||
if(leavingEventMap && getLeaderId() == quitter.getId()) return true;
|
||||
if(getPlayerCount() <= minPlayers) return true;
|
||||
if (leavingEventMap && getLeaderId() == quitter.getId()) {
|
||||
return true;
|
||||
}
|
||||
return getPlayerCount() <= minPlayers;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public final boolean isEventTeamTogether() {
|
||||
rL.lock();
|
||||
try {
|
||||
if(chars.size() <= 1) return true;
|
||||
if (chars.size() <= 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Iterator<Character> iterator = chars.values().iterator();
|
||||
Character mc = iterator.next();
|
||||
@@ -1133,7 +1177,9 @@ public class EventInstanceManager {
|
||||
|
||||
for (; iterator.hasNext(); ) {
|
||||
mc = iterator.next();
|
||||
if(mc.getMapId() != mapId) return false;
|
||||
if (mc.getMapId() != mapId) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -1146,10 +1192,11 @@ public class EventInstanceManager {
|
||||
List<Character> players = getPlayerList();
|
||||
|
||||
for (Character chr : players) {
|
||||
if(chr.getMapId() == warpFrom)
|
||||
if (chr.getMapId() == warpFrom) {
|
||||
chr.changeMap(warpTo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void warpEventTeam(int warpTo) {
|
||||
List<Character> players = getPlayerList();
|
||||
@@ -1163,10 +1210,11 @@ public class EventInstanceManager {
|
||||
List<Character> players = getPlayerList();
|
||||
|
||||
for (Character chr : players) {
|
||||
if(chr.getMapId() == warpFrom)
|
||||
if (chr.getMapId() == warpFrom) {
|
||||
chr.changeMap(warpTo, toSp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void warpEventTeamToMapSpawnPoint(int warpTo, int toSp) {
|
||||
List<Character> players = getPlayerList();
|
||||
@@ -1219,7 +1267,9 @@ public class EventInstanceManager {
|
||||
|
||||
public final void showClearEffect(boolean hasGate) {
|
||||
Character leader = getLeader();
|
||||
if(leader != null) showClearEffect(hasGate, leader.getMapId());
|
||||
if (leader != null) {
|
||||
showClearEffect(hasGate, leader.getMapId());
|
||||
}
|
||||
}
|
||||
|
||||
public final void showClearEffect(int mapId) {
|
||||
@@ -1348,7 +1398,9 @@ public class EventInstanceManager {
|
||||
}
|
||||
|
||||
public boolean activatedAllReactorsOnMap(MapleMap map, int minReactorId, int maxReactorId) {
|
||||
if(map == null) return true;
|
||||
if (map == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (Reactor mr : map.getReactorsByIdRange(minReactorId, maxReactorId)) {
|
||||
if (mr.getReactorType() != -1) {
|
||||
|
||||
@@ -54,7 +54,6 @@ import java.util.logging.Logger;
|
||||
//import jdk.nashorn.api.scripting.ScriptUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Matze
|
||||
* @author Ronan
|
||||
*/
|
||||
@@ -63,22 +62,22 @@ public class EventManager {
|
||||
private Channel cserv;
|
||||
private World wserv;
|
||||
private Server server;
|
||||
private EventScriptScheduler ess = new EventScriptScheduler();
|
||||
private Map<String, EventInstanceManager> instances = new HashMap<>();
|
||||
private Map<String, Integer> instanceLocks = new HashMap<>();
|
||||
private final EventScriptScheduler ess = new EventScriptScheduler();
|
||||
private final Map<String, EventInstanceManager> instances = new HashMap<>();
|
||||
private final Map<String, Integer> instanceLocks = new HashMap<>();
|
||||
private final Queue<Integer> queuedGuilds = new LinkedList<>();
|
||||
private final Map<Integer, Integer> queuedGuildLeaders = new HashMap<>();
|
||||
private List<Boolean> openedLobbys;
|
||||
private List<EventInstanceManager> readyInstances = new LinkedList<>();
|
||||
private final List<Boolean> openedLobbys;
|
||||
private final List<EventInstanceManager> readyInstances = new LinkedList<>();
|
||||
private Integer readyId = 0, onLoadInstances = 0;
|
||||
private Properties props = new Properties();
|
||||
private String name;
|
||||
private final Properties props = new Properties();
|
||||
private final String name;
|
||||
private MonitoredReentrantLock lobbyLock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.EM_LOBBY);
|
||||
private MonitoredReentrantLock queueLock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.EM_QUEUE);
|
||||
private MonitoredReentrantLock startLock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.EM_START);
|
||||
|
||||
private Set<Integer> playerPermit = new HashSet<>();
|
||||
private Semaphore startSemaphore = new Semaphore(7);
|
||||
private final Set<Integer> playerPermit = new HashSet<>();
|
||||
private final Semaphore startSemaphore = new Semaphore(7);
|
||||
|
||||
private static final int maxLobbys = 8; // an event manager holds up to this amount of concurrent lobbys
|
||||
|
||||
@@ -90,7 +89,9 @@ public class EventManager {
|
||||
this.name = name;
|
||||
|
||||
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() {
|
||||
@@ -318,10 +319,14 @@ public class EventManager {
|
||||
|
||||
private void freeLobbyInstance(String lobbyName) {
|
||||
Integer i = instanceLocks.get(lobbyName);
|
||||
if(i == null) return;
|
||||
if (i == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
instanceLocks.remove(lobbyName);
|
||||
if(i > -1) setLockLobby(i, false);
|
||||
if (i > -1) {
|
||||
setLockLobby(i, false);
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -380,7 +385,9 @@ public class EventManager {
|
||||
|
||||
//Expedition method: starts an expedition
|
||||
public boolean startInstance(int lobbyId, Expedition exped, Character leader) {
|
||||
if (this.isDisposed()) return false;
|
||||
if (this.isDisposed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
|
||||
@@ -391,10 +398,13 @@ public class EventManager {
|
||||
try {
|
||||
if (lobbyId == -1) {
|
||||
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;
|
||||
@@ -447,7 +457,9 @@ public class EventManager {
|
||||
}
|
||||
|
||||
public boolean startInstance(int lobbyId, Character chr, Character leader, int difficulty) {
|
||||
if (this.isDisposed()) return false;
|
||||
if (this.isDisposed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
|
||||
@@ -461,8 +473,7 @@ public class EventManager {
|
||||
if (lobbyId == -1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (!startLobbyInstance(lobbyId)) {
|
||||
return false;
|
||||
}
|
||||
@@ -485,7 +496,9 @@ public class EventManager {
|
||||
}
|
||||
eim.setLeader(leader);
|
||||
|
||||
if(chr != null) eim.registerPlayer(chr);
|
||||
if (chr != null) {
|
||||
eim.registerPlayer(chr);
|
||||
}
|
||||
|
||||
eim.startEvent();
|
||||
} catch (ScriptException | NoSuchMethodException ex) {
|
||||
@@ -516,7 +529,9 @@ public class EventManager {
|
||||
}
|
||||
|
||||
public boolean startInstance(int lobbyId, Party party, MapleMap map, Character leader) {
|
||||
if (this.isDisposed()) return false;
|
||||
if (this.isDisposed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
|
||||
@@ -527,10 +542,13 @@ public class EventManager {
|
||||
try {
|
||||
if (lobbyId == -1) {
|
||||
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;
|
||||
@@ -583,7 +601,9 @@ public class EventManager {
|
||||
}
|
||||
|
||||
public boolean startInstance(int lobbyId, Party party, MapleMap map, int difficulty, Character leader) {
|
||||
if (this.isDisposed()) return false;
|
||||
if (this.isDisposed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
|
||||
@@ -594,10 +614,13 @@ public class EventManager {
|
||||
try {
|
||||
if (lobbyId == -1) {
|
||||
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;
|
||||
@@ -654,7 +677,9 @@ public class EventManager {
|
||||
}
|
||||
|
||||
public boolean startInstance(int lobbyId, EventInstanceManager eim, String ldr, Character leader) {
|
||||
if (this.isDisposed()) return false;
|
||||
if (this.isDisposed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
|
||||
@@ -665,10 +690,13 @@ public class EventManager {
|
||||
try {
|
||||
if (lobbyId == -1) {
|
||||
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) {
|
||||
@@ -761,7 +789,9 @@ public class EventManager {
|
||||
private List<Integer> getNextGuildQueue() {
|
||||
synchronized (queuedGuilds) {
|
||||
Integer guildId = queuedGuilds.poll();
|
||||
if(guildId == null) return null;
|
||||
if (guildId == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
wserv.removeGuildQueued(guildId);
|
||||
Integer leaderId = queuedGuildLeaders.remove(guildId);
|
||||
@@ -773,7 +803,8 @@ public class EventManager {
|
||||
}
|
||||
|
||||
List<Integer> list = new ArrayList<>(2);
|
||||
list.add(guildId); list.add(leaderId);
|
||||
list.add(guildId);
|
||||
list.add(leaderId);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -791,7 +822,9 @@ public class EventManager {
|
||||
}
|
||||
|
||||
public byte addGuildToQueue(Integer guildId, Integer leaderId) {
|
||||
if(wserv.isGuildQueued(guildId)) return -1;
|
||||
if (wserv.isGuildQueued(guildId)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!isQueueFull()) {
|
||||
boolean canStartAhead;
|
||||
@@ -889,7 +922,9 @@ public class EventManager {
|
||||
int nextEventId;
|
||||
queueLock.lock();
|
||||
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++;
|
||||
nextEventId = readyId;
|
||||
|
||||
@@ -22,7 +22,6 @@ package scripting.event;
|
||||
import scripting.event.scheduler.EventScriptScheduler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ronan
|
||||
*/
|
||||
public class EventScheduledFuture {
|
||||
|
||||
@@ -36,7 +36,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Matze
|
||||
*/
|
||||
public class EventScriptManager extends AbstractScriptManager {
|
||||
@@ -51,6 +50,7 @@ public class EventScriptManager extends AbstractScriptManager {
|
||||
this.iv = iv;
|
||||
this.em = em;
|
||||
}
|
||||
|
||||
public Invocable iv;
|
||||
public EventManager em;
|
||||
}
|
||||
|
||||
@@ -36,18 +36,17 @@ import java.util.Map.Entry;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ronan
|
||||
*/
|
||||
public class EventScriptScheduler {
|
||||
|
||||
private boolean disposed = false;
|
||||
private int idleProcs = 0;
|
||||
private Map<Runnable, Long> registeredEntries = new HashMap<>();
|
||||
private final Map<Runnable, Long> registeredEntries = new HashMap<>();
|
||||
|
||||
private ScheduledFuture<?> schedulerTask = null;
|
||||
private MonitoredReentrantLock schedulerLock;
|
||||
private Runnable monitorTask = () -> runBaseSchedule();
|
||||
private final Runnable monitorTask = () -> runBaseSchedule();
|
||||
|
||||
public EventScriptScheduler() {
|
||||
schedulerLock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.EM_SCHDL, true);
|
||||
|
||||
@@ -27,7 +27,7 @@ import server.ItemInformationProvider.ScriptedItem;
|
||||
|
||||
public class ItemScriptManager {
|
||||
|
||||
private static ItemScriptManager instance = new ItemScriptManager();
|
||||
private static final ItemScriptManager instance = new ItemScriptManager();
|
||||
|
||||
public static ItemScriptManager getInstance() {
|
||||
return instance;
|
||||
|
||||
@@ -25,7 +25,6 @@ import client.Client;
|
||||
import scripting.AbstractPlayerInteraction;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevintjuh93
|
||||
*/
|
||||
public class ItemScriptMethods extends AbstractPlayerInteraction {
|
||||
|
||||
@@ -30,7 +30,7 @@ import tools.PacketCreator;
|
||||
|
||||
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) {
|
||||
super(c);
|
||||
|
||||
@@ -70,19 +70,18 @@ import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Matze
|
||||
*/
|
||||
public class NPCConversationManager extends AbstractPlayerInteraction {
|
||||
|
||||
private int npc;
|
||||
private final int npc;
|
||||
private int npcOid;
|
||||
private String scriptName;
|
||||
private String getText;
|
||||
private boolean itemScript;
|
||||
private List<PartyCharacter> otherParty;
|
||||
|
||||
private Map<Integer, String> npcDefaultTalks = new HashMap<>();
|
||||
private final Map<Integer, String> npcDefaultTalks = new HashMap<>();
|
||||
|
||||
private String getDefaultTalk(int npcid) {
|
||||
String talk = npcDefaultTalks.get(npcid);
|
||||
@@ -455,11 +454,7 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
if (getPlayer().getMerchantMeso() == 0) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return getPlayer().getMerchantMeso() != 0;
|
||||
}
|
||||
|
||||
public void showFredrick() {
|
||||
@@ -654,17 +649,11 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
|
||||
if (!c.getChannelServer().getMapFactory().getMap(980000101 + field * 100).getAllPlayer().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
if (!c.getChannelServer().getMapFactory().getMap(980000102 + field * 100).getAllPlayer().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return !c.getChannelServer().getMapFactory().getMap(980000102 + field * 100).getAllPlayer().isEmpty();
|
||||
}
|
||||
|
||||
public boolean fieldLobbied(int field) {
|
||||
if (!c.getChannelServer().getMapFactory().getMap(980000100 + field * 100).getAllPlayer().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return !c.getChannelServer().getMapFactory().getMap(980000100 + field * 100).getAllPlayer().isEmpty();
|
||||
}
|
||||
|
||||
public void cpqLobby(int field) {
|
||||
@@ -903,17 +892,11 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
|
||||
if (!c.getChannelServer().getMapFactory().getMap(980031100 + field * 1000).getAllPlayer().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
if (!c.getChannelServer().getMapFactory().getMap(980031200 + field * 1000).getAllPlayer().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return !c.getChannelServer().getMapFactory().getMap(980031200 + field * 1000).getAllPlayer().isEmpty();
|
||||
}
|
||||
|
||||
public boolean fieldLobbied2(int field) {
|
||||
if (!c.getChannelServer().getMapFactory().getMap(980031000 + field * 1000).getAllPlayer().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return !c.getChannelServer().getMapFactory().getMap(980031000 + field * 1000).getAllPlayer().isEmpty();
|
||||
}
|
||||
|
||||
public void cpqLobby2(int field) {
|
||||
|
||||
@@ -37,7 +37,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Matze
|
||||
*/
|
||||
public class NPCScriptManager extends AbstractScriptManager {
|
||||
|
||||
@@ -29,12 +29,11 @@ import server.quest.actions.ExpAction;
|
||||
import server.quest.actions.MesoAction;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author RMZero213
|
||||
*/
|
||||
public class QuestActionManager extends NPCConversationManager {
|
||||
private boolean start; // this is if the script in question is start or end
|
||||
private int quest;
|
||||
private final boolean start; // this is if the script in question is start or end
|
||||
private final int quest;
|
||||
|
||||
public QuestActionManager(Client c, int quest, int npc, boolean start) {
|
||||
super(c, npc, null);
|
||||
|
||||
@@ -35,7 +35,6 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author RMZero213
|
||||
*/
|
||||
public class QuestScriptManager extends AbstractScriptManager {
|
||||
|
||||
@@ -153,10 +153,14 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
|
||||
|
||||
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();
|
||||
if(chr == null) return;
|
||||
if (chr == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (!delayed) {
|
||||
|
||||
@@ -59,7 +59,8 @@ public class ReactorScriptManager extends AbstractScriptManager {
|
||||
}
|
||||
|
||||
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) {
|
||||
FilePrinter.printError(FilePrinter.REACTOR + reactor.getId() + ".txt", e);
|
||||
|
||||
Reference in New Issue
Block a user