Reformat and clean up "scripting" package
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -60,29 +60,28 @@ import java.util.logging.Level;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Matze
|
* @author Matze
|
||||||
* @author Ronan
|
* @author Ronan
|
||||||
*/
|
*/
|
||||||
public class EventInstanceManager {
|
public class EventInstanceManager {
|
||||||
private Map<Integer, Character> chars = new HashMap<>();
|
private final Map<Integer, Character> chars = new HashMap<>();
|
||||||
private int leaderId = -1;
|
private int leaderId = -1;
|
||||||
private List<Monster> mobs = new LinkedList<>();
|
private final List<Monster> mobs = new LinkedList<>();
|
||||||
private Map<Character, Integer> killCount = new HashMap<>();
|
private final Map<Character, Integer> killCount = new HashMap<>();
|
||||||
private EventManager em;
|
private EventManager em;
|
||||||
private EventScriptScheduler ess;
|
private EventScriptScheduler ess;
|
||||||
private MapManager mapManager;
|
private MapManager mapManager;
|
||||||
private String name;
|
private String name;
|
||||||
private Properties props = new Properties();
|
private final Properties props = new Properties();
|
||||||
private Map<String, Object> objectProps = new HashMap<>();
|
private final Map<String, Object> objectProps = new HashMap<>();
|
||||||
private long timeStarted = 0;
|
private long timeStarted = 0;
|
||||||
private long eventTime = 0;
|
private long eventTime = 0;
|
||||||
private Expedition expedition = null;
|
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 final MonitoredReentrantReadWriteLock lock = new MonitoredReentrantReadWriteLock(MonitoredLockType.EIM, true);
|
||||||
private MonitoredReadLock rL = MonitoredReadLockFactory.createLock(lock);
|
private final MonitoredReadLock rL = MonitoredReadLockFactory.createLock(lock);
|
||||||
private MonitoredWriteLock wL = MonitoredWriteLockFactory.createLock(lock);
|
private final MonitoredWriteLock wL = MonitoredWriteLockFactory.createLock(lock);
|
||||||
|
|
||||||
private MonitoredReentrantLock pL = MonitoredReentrantLockFactory.createLock(MonitoredLockType.EIM_PARTY, true);
|
private MonitoredReentrantLock pL = MonitoredReentrantLockFactory.createLock(MonitoredLockType.EIM_PARTY, true);
|
||||||
private MonitoredReentrantLock sL = MonitoredReentrantLockFactory.createLock(MonitoredLockType.EIM_SCRIPT, true);
|
private MonitoredReentrantLock sL = MonitoredReentrantLockFactory.createLock(MonitoredLockType.EIM_SCRIPT, true);
|
||||||
@@ -93,22 +92,22 @@ public class EventInstanceManager {
|
|||||||
private boolean eventStarted = false;
|
private boolean eventStarted = false;
|
||||||
|
|
||||||
// multi-leveled PQ rewards!
|
// multi-leveled PQ rewards!
|
||||||
private Map<Integer, List<Integer>> collectionSet = new HashMap<>(YamlConfig.config.server.MAX_EVENT_LEVELS);
|
private final 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 final 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, Integer> collectionExp = new HashMap<>(YamlConfig.config.server.MAX_EVENT_LEVELS);
|
||||||
|
|
||||||
// Exp/Meso rewards by CLEAR on a stage
|
// Exp/Meso rewards by CLEAR on a stage
|
||||||
private List<Integer> onMapClearExp = new ArrayList<>();
|
private final List<Integer> onMapClearExp = new ArrayList<>();
|
||||||
private List<Integer> onMapClearMeso = new ArrayList<>();
|
private final List<Integer> onMapClearMeso = new ArrayList<>();
|
||||||
|
|
||||||
// registers player status on an event (null on this Map structure equals to 0)
|
// 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
|
// 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.
|
// 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) {
|
public EventInstanceManager(EventManager em, String name) {
|
||||||
this.em = em;
|
this.em = em;
|
||||||
@@ -176,7 +175,9 @@ public class EventInstanceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void giveEventPlayersExp(int gain, int mapId) {
|
public void giveEventPlayersExp(int gain, int mapId) {
|
||||||
if(gain == 0) return;
|
if (gain == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
List<Character> players = getPlayerList();
|
List<Character> players = getPlayerList();
|
||||||
|
|
||||||
@@ -184,10 +185,11 @@ public class EventInstanceManager {
|
|||||||
for (Character mc : players) {
|
for (Character mc : players) {
|
||||||
mc.gainExp(gain * mc.getExpRate(), true, true);
|
mc.gainExp(gain * mc.getExpRate(), true, true);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
for (Character mc : players) {
|
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) {
|
public void giveEventPlayersMeso(int gain, int mapId) {
|
||||||
if(gain == 0) return;
|
if (gain == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
List<Character> players = getPlayerList();
|
List<Character> players = getPlayerList();
|
||||||
|
|
||||||
@@ -205,10 +209,11 @@ public class EventInstanceManager {
|
|||||||
for (Character mc : players) {
|
for (Character mc : players) {
|
||||||
mc.gainMeso(gain * mc.getMesoRate());
|
mc.gainMeso(gain * mc.getMesoRate());
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
for (Character mc : players) {
|
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) {
|
public void changedMap(final Character chr, final int mapId) {
|
||||||
try {
|
try {
|
||||||
invokeScriptFunction("changedMap", EventInstanceManager.this, chr, mapId);
|
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) {
|
public void afterChangedMap(final Character chr, final int mapId) {
|
||||||
try {
|
try {
|
||||||
invokeScriptFunction("afterChangedMap", EventInstanceManager.this, chr, mapId);
|
invokeScriptFunction("afterChangedMap", EventInstanceManager.this, chr, mapId);
|
||||||
} catch (ScriptException | NoSuchMethodException ex) {} // optional
|
} catch (ScriptException | NoSuchMethodException ex) {
|
||||||
|
} // optional
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void changedLeader(final PartyCharacter ldr) {
|
public synchronized void changedLeader(final PartyCharacter ldr) {
|
||||||
@@ -505,33 +512,38 @@ public class EventInstanceManager {
|
|||||||
public void friendlyKilled(final Monster mob, final boolean hasKiller) {
|
public void friendlyKilled(final Monster mob, final boolean hasKiller) {
|
||||||
try {
|
try {
|
||||||
invokeScriptFunction("friendlyKilled", mob, EventInstanceManager.this, hasKiller);
|
invokeScriptFunction("friendlyKilled", mob, EventInstanceManager.this, hasKiller);
|
||||||
} catch (ScriptException | NoSuchMethodException ex) {} //optional
|
} catch (ScriptException | NoSuchMethodException ex) {
|
||||||
|
} //optional
|
||||||
}
|
}
|
||||||
|
|
||||||
public void friendlyDamaged(final Monster mob) {
|
public void friendlyDamaged(final Monster mob) {
|
||||||
try {
|
try {
|
||||||
invokeScriptFunction("friendlyDamaged", EventInstanceManager.this, mob);
|
invokeScriptFunction("friendlyDamaged", EventInstanceManager.this, mob);
|
||||||
} catch (ScriptException | NoSuchMethodException ex) {} // optional
|
} catch (ScriptException | NoSuchMethodException ex) {
|
||||||
|
} // optional
|
||||||
}
|
}
|
||||||
|
|
||||||
public void friendlyItemDrop(final Monster mob) {
|
public void friendlyItemDrop(final Monster mob) {
|
||||||
try {
|
try {
|
||||||
invokeScriptFunction("friendlyItemDrop", EventInstanceManager.this, mob);
|
invokeScriptFunction("friendlyItemDrop", EventInstanceManager.this, mob);
|
||||||
} catch (ScriptException | NoSuchMethodException ex) {} // optional
|
} catch (ScriptException | NoSuchMethodException ex) {
|
||||||
|
} // optional
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playerKilled(final Character chr) {
|
public void playerKilled(final Character chr) {
|
||||||
ThreadManager.getInstance().newTask(() -> {
|
ThreadManager.getInstance().newTask(() -> {
|
||||||
try {
|
try {
|
||||||
invokeScriptFunction("playerDead", EventInstanceManager.this, chr);
|
invokeScriptFunction("playerDead", EventInstanceManager.this, chr);
|
||||||
} catch (ScriptException | NoSuchMethodException ex) {} // optional
|
} catch (ScriptException | NoSuchMethodException ex) {
|
||||||
|
} // optional
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reviveMonster(final Monster mob) {
|
public void reviveMonster(final Monster mob) {
|
||||||
try {
|
try {
|
||||||
invokeScriptFunction("monsterRevive", EventInstanceManager.this, mob);
|
invokeScriptFunction("monsterRevive", EventInstanceManager.this, mob);
|
||||||
} catch (ScriptException | NoSuchMethodException ex) {} // optional
|
} catch (ScriptException | NoSuchMethodException ex) {
|
||||||
|
} // optional
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean revivePlayer(final Character chr) {
|
public boolean revivePlayer(final Character chr) {
|
||||||
@@ -540,7 +552,8 @@ public class EventInstanceManager {
|
|||||||
if (b instanceof Boolean) {
|
if (b instanceof Boolean) {
|
||||||
return (Boolean) b;
|
return (Boolean) b;
|
||||||
}
|
}
|
||||||
} catch (ScriptException | NoSuchMethodException ex) {} // optional
|
} catch (ScriptException | NoSuchMethodException ex) {
|
||||||
|
} // optional
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -584,7 +597,9 @@ public class EventInstanceManager {
|
|||||||
public void dispose() {
|
public void dispose() {
|
||||||
rL.lock();
|
rL.lock();
|
||||||
try {
|
try {
|
||||||
for(Character chr: chars.values()) chr.setEventInstance(null);
|
for (Character chr : chars.values()) {
|
||||||
|
chr.setEventInstance(null);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
rL.unlock();
|
rL.unlock();
|
||||||
}
|
}
|
||||||
@@ -593,7 +608,9 @@ public class EventInstanceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void dispose(boolean shutdown) { // should not trigger any event script method after disposed
|
public synchronized void dispose(boolean shutdown) { // should not trigger any event script method after disposed
|
||||||
if(disposed) return;
|
if (disposed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
invokeScriptFunction("dispose", EventInstanceManager.this);
|
invokeScriptFunction("dispose", EventInstanceManager.this);
|
||||||
@@ -606,7 +623,9 @@ public class EventInstanceManager {
|
|||||||
|
|
||||||
wL.lock();
|
wL.lock();
|
||||||
try {
|
try {
|
||||||
for(Character chr: chars.values()) chr.setEventInstance(null);
|
for (Character chr : chars.values()) {
|
||||||
|
chr.setEventInstance(null);
|
||||||
|
}
|
||||||
chars.clear();
|
chars.clear();
|
||||||
mobs.clear();
|
mobs.clear();
|
||||||
ess = null;
|
ess = null;
|
||||||
@@ -628,7 +647,9 @@ public class EventInstanceManager {
|
|||||||
|
|
||||||
sL.lock();
|
sL.lock();
|
||||||
try {
|
try {
|
||||||
if(!eventCleared) em.disposeInstance(name);
|
if (!eventCleared) {
|
||||||
|
em.disposeInstance(name);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
sL.unlock();
|
sL.unlock();
|
||||||
}
|
}
|
||||||
@@ -901,12 +922,16 @@ public class EventInstanceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Integer getClearStageExp(int stage) { //stage counts from ONE.
|
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);
|
return onMapClearExp.get(stage - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getClearStageMeso(int stage) { //stage counts from ONE.
|
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);
|
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) {
|
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
|
// 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
|
eventLevel--; //event level starts from 1
|
||||||
|
|
||||||
List<Integer> rewardIds = convertToIntegerList(rwds);
|
List<Integer> rewardIds = convertToIntegerList(rwds);
|
||||||
@@ -970,7 +997,9 @@ public class EventInstanceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private byte getRewardListRequirements(int level) {
|
private byte getRewardListRequirements(int level) {
|
||||||
if(level >= collectionSet.size()) return 0;
|
if (level >= collectionSet.size()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
byte rewardTypes = 0;
|
byte rewardTypes = 0;
|
||||||
List<Integer> list = collectionSet.get(level);
|
List<Integer> list = collectionSet.get(level);
|
||||||
@@ -987,9 +1016,10 @@ public class EventInstanceManager {
|
|||||||
|
|
||||||
//iterating over all valid inventory types
|
//iterating over all valid inventory types
|
||||||
for (byte type = 1; type <= 5; type++) {
|
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 false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1006,7 +1036,9 @@ public class EventInstanceManager {
|
|||||||
rL.lock();
|
rL.lock();
|
||||||
try {
|
try {
|
||||||
eventLevel--; //event level starts counting from 1
|
eventLevel--; //event level starts counting from 1
|
||||||
if(eventLevel >= collectionSet.size()) return true;
|
if (eventLevel >= collectionSet.size()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
rewardsSet = collectionSet.get(eventLevel);
|
rewardsSet = collectionSet.get(eventLevel);
|
||||||
rewardsQty = collectionQty.get(eventLevel);
|
rewardsQty = collectionQty.get(eventLevel);
|
||||||
@@ -1016,20 +1048,28 @@ public class EventInstanceManager {
|
|||||||
rL.unlock();
|
rL.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(rewardExp == null) rewardExp = 0;
|
if (rewardExp == null) {
|
||||||
|
rewardExp = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (rewardsSet == null || rewardsSet.isEmpty()) {
|
if (rewardsSet == null || rewardsSet.isEmpty()) {
|
||||||
if(rewardExp > 0) player.gainExp(rewardExp);
|
if (rewardExp > 0) {
|
||||||
|
player.gainExp(rewardExp);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!hasRewardSlot(player, eventLevel)) return false;
|
if (!hasRewardSlot(player, eventLevel)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
AbstractPlayerInteraction api = player.getAbstractPlayerInteraction();
|
AbstractPlayerInteraction api = player.getAbstractPlayerInteraction();
|
||||||
int rnd = (int) Math.floor(Math.random() * rewardsSet.size());
|
int rnd = (int) Math.floor(Math.random() * rewardsSet.size());
|
||||||
|
|
||||||
api.gainItem(rewardsSet.get(rnd), rewardsQty.get(rnd).shortValue());
|
api.gainItem(rewardsSet.get(rnd), rewardsQty.get(rnd).shortValue());
|
||||||
if(rewardExp > 0) player.gainExp(rewardExp);
|
if (rewardExp > 0) {
|
||||||
|
player.gainExp(rewardExp);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1085,47 +1125,51 @@ public class EventInstanceManager {
|
|||||||
|
|
||||||
private boolean isEventTeamLeaderOn() {
|
private boolean isEventTeamLeaderOn() {
|
||||||
for (Character chr : getPlayers()) {
|
for (Character chr : getPlayers()) {
|
||||||
if(chr.getId() == getLeaderId()) return true;
|
if (chr.getId() == getLeaderId()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean checkEventTeamLacking(boolean leavingEventMap, int minPlayers) {
|
public final boolean checkEventTeamLacking(boolean leavingEventMap, int minPlayers) {
|
||||||
if(eventCleared && getPlayerCount() > 1) return false;
|
if (eventCleared && getPlayerCount() > 1) {
|
||||||
|
|
||||||
if(!eventCleared && leavingEventMap && !isEventTeamLeaderOn()) return true;
|
|
||||||
if(getPlayerCount() < minPlayers) return true;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!eventCleared && leavingEventMap && !isEventTeamLeaderOn()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return getPlayerCount() < minPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
public final boolean isExpeditionTeamLackingNow(boolean leavingEventMap, int minPlayers, Character quitter) {
|
public final boolean isExpeditionTeamLackingNow(boolean leavingEventMap, int minPlayers, Character quitter) {
|
||||||
if (eventCleared) {
|
if (eventCleared) {
|
||||||
if(leavingEventMap && getPlayerCount() <= 1) return true;
|
return leavingEventMap && getPlayerCount() <= 1;
|
||||||
} else {
|
} else {
|
||||||
// thanks Conrad for noticing expeditions don't need to have neither the leader nor meet the minimum requirement inside the event
|
// 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) {
|
public final boolean isEventTeamLackingNow(boolean leavingEventMap, int minPlayers, Character quitter) {
|
||||||
if (eventCleared) {
|
if (eventCleared) {
|
||||||
if(leavingEventMap && getPlayerCount() <= 1) return true;
|
return leavingEventMap && getPlayerCount() <= 1;
|
||||||
} else {
|
} else {
|
||||||
if(leavingEventMap && getLeaderId() == quitter.getId()) return true;
|
if (leavingEventMap && getLeaderId() == quitter.getId()) {
|
||||||
if(getPlayerCount() <= minPlayers) return true;
|
return true;
|
||||||
|
}
|
||||||
|
return getPlayerCount() <= minPlayers;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isEventTeamTogether() {
|
public final boolean isEventTeamTogether() {
|
||||||
rL.lock();
|
rL.lock();
|
||||||
try {
|
try {
|
||||||
if(chars.size() <= 1) return true;
|
if (chars.size() <= 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Iterator<Character> iterator = chars.values().iterator();
|
Iterator<Character> iterator = chars.values().iterator();
|
||||||
Character mc = iterator.next();
|
Character mc = iterator.next();
|
||||||
@@ -1133,7 +1177,9 @@ public class EventInstanceManager {
|
|||||||
|
|
||||||
for (; iterator.hasNext(); ) {
|
for (; iterator.hasNext(); ) {
|
||||||
mc = iterator.next();
|
mc = iterator.next();
|
||||||
if(mc.getMapId() != mapId) return false;
|
if (mc.getMapId() != mapId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -1146,10 +1192,11 @@ public class EventInstanceManager {
|
|||||||
List<Character> players = getPlayerList();
|
List<Character> players = getPlayerList();
|
||||||
|
|
||||||
for (Character chr : players) {
|
for (Character chr : players) {
|
||||||
if(chr.getMapId() == warpFrom)
|
if (chr.getMapId() == warpFrom) {
|
||||||
chr.changeMap(warpTo);
|
chr.changeMap(warpTo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public final void warpEventTeam(int warpTo) {
|
public final void warpEventTeam(int warpTo) {
|
||||||
List<Character> players = getPlayerList();
|
List<Character> players = getPlayerList();
|
||||||
@@ -1163,10 +1210,11 @@ public class EventInstanceManager {
|
|||||||
List<Character> players = getPlayerList();
|
List<Character> players = getPlayerList();
|
||||||
|
|
||||||
for (Character chr : players) {
|
for (Character chr : players) {
|
||||||
if(chr.getMapId() == warpFrom)
|
if (chr.getMapId() == warpFrom) {
|
||||||
chr.changeMap(warpTo, toSp);
|
chr.changeMap(warpTo, toSp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public final void warpEventTeamToMapSpawnPoint(int warpTo, int toSp) {
|
public final void warpEventTeamToMapSpawnPoint(int warpTo, int toSp) {
|
||||||
List<Character> players = getPlayerList();
|
List<Character> players = getPlayerList();
|
||||||
@@ -1219,7 +1267,9 @@ public class EventInstanceManager {
|
|||||||
|
|
||||||
public final void showClearEffect(boolean hasGate) {
|
public final void showClearEffect(boolean hasGate) {
|
||||||
Character leader = getLeader();
|
Character leader = getLeader();
|
||||||
if(leader != null) showClearEffect(hasGate, leader.getMapId());
|
if (leader != null) {
|
||||||
|
showClearEffect(hasGate, leader.getMapId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void showClearEffect(int mapId) {
|
public final void showClearEffect(int mapId) {
|
||||||
@@ -1348,7 +1398,9 @@ public class EventInstanceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean activatedAllReactorsOnMap(MapleMap map, int minReactorId, int maxReactorId) {
|
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)) {
|
for (Reactor mr : map.getReactorsByIdRange(minReactorId, maxReactorId)) {
|
||||||
if (mr.getReactorType() != -1) {
|
if (mr.getReactorType() != -1) {
|
||||||
|
|||||||
@@ -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,22 +62,22 @@ 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
|
||||||
|
|
||||||
@@ -90,7 +89,9 @@ public class EventManager {
|
|||||||
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() {
|
||||||
@@ -318,10 +319,14 @@ public class EventManager {
|
|||||||
|
|
||||||
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() {
|
||||||
@@ -380,7 +385,9 @@ public class EventManager {
|
|||||||
|
|
||||||
//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)) {
|
||||||
@@ -391,10 +398,13 @@ public class EventManager {
|
|||||||
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;
|
||||||
@@ -447,7 +457,9 @@ public class EventManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)) {
|
||||||
@@ -461,8 +473,7 @@ public class EventManager {
|
|||||||
if (lobbyId == -1) {
|
if (lobbyId == -1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (!startLobbyInstance(lobbyId)) {
|
if (!startLobbyInstance(lobbyId)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -485,7 +496,9 @@ public class EventManager {
|
|||||||
}
|
}
|
||||||
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) {
|
||||||
@@ -516,7 +529,9 @@ public class EventManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)) {
|
||||||
@@ -527,10 +542,13 @@ public class EventManager {
|
|||||||
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;
|
||||||
@@ -583,7 +601,9 @@ public class EventManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)) {
|
||||||
@@ -594,10 +614,13 @@ public class EventManager {
|
|||||||
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;
|
||||||
@@ -654,7 +677,9 @@ public class EventManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)) {
|
||||||
@@ -665,10 +690,13 @@ public class EventManager {
|
|||||||
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) {
|
||||||
@@ -761,7 +789,9 @@ public class EventManager {
|
|||||||
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);
|
||||||
@@ -773,7 +803,8 @@ public class EventManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -791,7 +822,9 @@ public class EventManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
@@ -889,7 +922,9 @@ public class EventManager {
|
|||||||
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;
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ package scripting.event;
|
|||||||
import scripting.event.scheduler.EventScriptScheduler;
|
import scripting.event.scheduler.EventScriptScheduler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Ronan
|
* @author Ronan
|
||||||
*/
|
*/
|
||||||
public class EventScheduledFuture {
|
public class EventScheduledFuture {
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,7 +27,7 @@ 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;
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import client.Client;
|
|||||||
import scripting.AbstractPlayerInteraction;
|
import scripting.AbstractPlayerInteraction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author kevintjuh93
|
* @author kevintjuh93
|
||||||
*/
|
*/
|
||||||
public class ItemScriptMethods extends AbstractPlayerInteraction {
|
public class ItemScriptMethods extends AbstractPlayerInteraction {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ 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);
|
||||||
|
|||||||
@@ -70,19 +70,18 @@ import java.util.List;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Matze
|
* @author Matze
|
||||||
*/
|
*/
|
||||||
public class NPCConversationManager extends AbstractPlayerInteraction {
|
public class NPCConversationManager extends AbstractPlayerInteraction {
|
||||||
|
|
||||||
private int npc;
|
private final int npc;
|
||||||
private int npcOid;
|
private int npcOid;
|
||||||
private String scriptName;
|
private String scriptName;
|
||||||
private String getText;
|
private String getText;
|
||||||
private boolean itemScript;
|
private boolean itemScript;
|
||||||
private List<PartyCharacter> otherParty;
|
private List<PartyCharacter> otherParty;
|
||||||
|
|
||||||
private Map<Integer, String> npcDefaultTalks = new HashMap<>();
|
private final Map<Integer, String> npcDefaultTalks = new HashMap<>();
|
||||||
|
|
||||||
private String getDefaultTalk(int npcid) {
|
private String getDefaultTalk(int npcid) {
|
||||||
String talk = npcDefaultTalks.get(npcid);
|
String talk = npcDefaultTalks.get(npcid);
|
||||||
@@ -455,11 +454,7 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getPlayer().getMerchantMeso() == 0) {
|
return getPlayer().getMerchantMeso() != 0;
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showFredrick() {
|
public void showFredrick() {
|
||||||
@@ -654,17 +649,11 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
|
|||||||
if (!c.getChannelServer().getMapFactory().getMap(980000101 + field * 100).getAllPlayer().isEmpty()) {
|
if (!c.getChannelServer().getMapFactory().getMap(980000101 + field * 100).getAllPlayer().isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!c.getChannelServer().getMapFactory().getMap(980000102 + field * 100).getAllPlayer().isEmpty()) {
|
return !c.getChannelServer().getMapFactory().getMap(980000102 + field * 100).getAllPlayer().isEmpty();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean fieldLobbied(int field) {
|
public boolean fieldLobbied(int field) {
|
||||||
if (!c.getChannelServer().getMapFactory().getMap(980000100 + field * 100).getAllPlayer().isEmpty()) {
|
return !c.getChannelServer().getMapFactory().getMap(980000100 + field * 100).getAllPlayer().isEmpty();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cpqLobby(int field) {
|
public void cpqLobby(int field) {
|
||||||
@@ -903,17 +892,11 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
|
|||||||
if (!c.getChannelServer().getMapFactory().getMap(980031100 + field * 1000).getAllPlayer().isEmpty()) {
|
if (!c.getChannelServer().getMapFactory().getMap(980031100 + field * 1000).getAllPlayer().isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!c.getChannelServer().getMapFactory().getMap(980031200 + field * 1000).getAllPlayer().isEmpty()) {
|
return !c.getChannelServer().getMapFactory().getMap(980031200 + field * 1000).getAllPlayer().isEmpty();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean fieldLobbied2(int field) {
|
public boolean fieldLobbied2(int field) {
|
||||||
if (!c.getChannelServer().getMapFactory().getMap(980031000 + field * 1000).getAllPlayer().isEmpty()) {
|
return !c.getChannelServer().getMapFactory().getMap(980031000 + field * 1000).getAllPlayer().isEmpty();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cpqLobby2(int field) {
|
public void cpqLobby2(int field) {
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ 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 {
|
||||||
|
|||||||
@@ -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) {
|
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) {
|
||||||
|
|||||||
@@ -59,7 +59,8 @@ 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