Reformat and clean up "scripting" package

This commit is contained in:
P0nk committed 2021-09-09 23:26:45 +02:00
1 parent 9b1dc76854
commit d389665bd7
16 files changed
+3382 -3314

No files matched your search

File diff suppressed because it is too large. Load diff
@@ -32,7 +32,6 @@ import java.io.FileReader;
import java.io.IOException;
/**
*
* @author Matze
*/
public abstract class AbstractScriptManager {
File diff suppressed because it is too large. Load diff
+122 -87
View File
@@ -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() {
@@ -107,12 +108,12 @@ public class EventManager {
}
Collection<EventInstanceManager> eimList;
synchronized(instances) {
synchronized (instances) {
eimList = getInstances();
instances.clear();
}
for(EventInstanceManager eim : eimList) {
for (EventInstanceManager eim : eimList) {
eim.dispose(true);
}
@@ -126,7 +127,7 @@ public class EventManager {
queueLock.unlock();
}
for(EventInstanceManager eim : readyEims) {
for (EventInstanceManager eim : readyEims) {
eim.dispose(true);
}
@@ -228,7 +229,7 @@ public class EventManager {
public EventInstanceManager newInstance(String name) throws EventInstanceInProgressException {
EventInstanceManager ret = getReadyInstance();
if(ret == null) {
if (ret == null) {
ret = new EventInstanceManager(this, name);
} else {
ret.setName(name);
@@ -305,7 +306,7 @@ public class EventManager {
lobbyId = maxLobbys - 1;
}
if(!openedLobbys.get(lobbyId)) {
if (!openedLobbys.get(lobbyId)) {
openedLobbys.set(lobbyId, true);
return true;
}
@@ -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() {
@@ -347,7 +352,7 @@ public class EventManager {
return null;
}
while(true) {
while (true) {
Throwable t = a;
a = a.getCause();
@@ -380,21 +385,26 @@ 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)) {
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
playerPermit.add(leader.getId());
startLock.lock();
try {
try {
if(lobbyId == -1) {
if (lobbyId == -1) {
lobbyId = availableLobbyInstance();
if(lobbyId == -1) return false;
}
else {
if(!startLobbyInstance(lobbyId)) return false;
if (lobbyId == -1) {
return false;
}
} else {
if (!startLobbyInstance(lobbyId)) {
return false;
}
}
EventInstanceManager eim;
@@ -407,7 +417,7 @@ public class EventManager {
throw e;
}
if(lobbyId > -1) {
if (lobbyId > -1) {
setLockLobby(lobbyId, false);
}
return false;
@@ -430,7 +440,7 @@ public class EventManager {
startSemaphore.release();
}
}
} catch(InterruptedException ie) {
} catch (InterruptedException ie) {
playerPermit.remove(leader.getId());
}
@@ -447,23 +457,24 @@ 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)) {
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
playerPermit.add(leader.getId());
startLock.lock();
try {
try {
if(lobbyId == -1) {
if (lobbyId == -1) {
lobbyId = availableLobbyInstance();
if(lobbyId == -1) {
if (lobbyId == -1) {
return false;
}
}
else {
if(!startLobbyInstance(lobbyId)) {
} else {
if (!startLobbyInstance(lobbyId)) {
return false;
}
}
@@ -478,14 +489,16 @@ public class EventManager {
throw e;
}
if(lobbyId > -1) {
if (lobbyId > -1) {
setLockLobby(lobbyId, false);
}
return false;
}
eim.setLeader(leader);
if(chr != null) eim.registerPlayer(chr);
if (chr != null) {
eim.registerPlayer(chr);
}
eim.startEvent();
} catch (ScriptException | NoSuchMethodException ex) {
@@ -499,7 +512,7 @@ public class EventManager {
startSemaphore.release();
}
}
} catch(InterruptedException ie) {
} catch (InterruptedException ie) {
playerPermit.remove(leader.getId());
}
@@ -516,21 +529,26 @@ 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)) {
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
playerPermit.add(leader.getId());
startLock.lock();
try {
try {
if(lobbyId == -1) {
if (lobbyId == -1) {
lobbyId = availableLobbyInstance();
if(lobbyId == -1) return false;
}
else {
if(!startLobbyInstance(lobbyId)) return false;
if (lobbyId == -1) {
return false;
}
} else {
if (!startLobbyInstance(lobbyId)) {
return false;
}
}
EventInstanceManager eim;
@@ -543,7 +561,7 @@ public class EventManager {
throw e;
}
if(lobbyId > -1) {
if (lobbyId > -1) {
setLockLobby(lobbyId, false);
}
return false;
@@ -566,7 +584,7 @@ public class EventManager {
startSemaphore.release();
}
}
} catch(InterruptedException ie) {
} catch (InterruptedException ie) {
playerPermit.remove(leader.getId());
}
@@ -583,21 +601,26 @@ 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)) {
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
playerPermit.add(leader.getId());
startLock.lock();
try {
try {
if(lobbyId == -1) {
if (lobbyId == -1) {
lobbyId = availableLobbyInstance();
if(lobbyId == -1) return false;
}
else {
if(!startLobbyInstance(lobbyId)) return false;
if (lobbyId == -1) {
return false;
}
} else {
if (!startLobbyInstance(lobbyId)) {
return false;
}
}
EventInstanceManager eim;
@@ -610,7 +633,7 @@ public class EventManager {
throw e;
}
if(lobbyId > -1) {
if (lobbyId > -1) {
setLockLobby(lobbyId, false);
}
return false;
@@ -633,7 +656,7 @@ public class EventManager {
startSemaphore.release();
}
}
} catch(InterruptedException ie) {
} catch (InterruptedException ie) {
playerPermit.remove(leader.getId());
}
@@ -654,25 +677,30 @@ 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)) {
if (!playerPermit.contains(leader.getId()) && startSemaphore.tryAcquire(7777, TimeUnit.MILLISECONDS)) {
playerPermit.add(leader.getId());
startLock.lock();
try {
try {
if(lobbyId == -1) {
if (lobbyId == -1) {
lobbyId = availableLobbyInstance();
if(lobbyId == -1) return false;
}
else {
if(!startLobbyInstance(lobbyId)) return false;
if (lobbyId == -1) {
return false;
}
} else {
if (!startLobbyInstance(lobbyId)) {
return false;
}
}
if(eim == null) {
if(lobbyId > -1) {
if (eim == null) {
if (lobbyId > -1) {
setLockLobby(lobbyId, false);
}
return false;
@@ -695,7 +723,7 @@ public class EventManager {
startSemaphore.release();
}
}
} catch(InterruptedException ie) {
} catch (InterruptedException ie) {
playerPermit.remove(leader.getId());
}
@@ -738,14 +766,14 @@ public class EventManager {
}
public Monster getMonster(int mid) {
return(LifeFactory.getMonster(mid));
return (LifeFactory.getMonster(mid));
}
private void exportReadyGuild(Integer 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()
+ " 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.";
+ " 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.";
mg.dropMessage(6, callout);
}
@@ -753,49 +781,54 @@ public class EventManager {
private void exportMovedQueueToGuild(Integer guildId, int place) {
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()
+ " 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);
}
private List<Integer> getNextGuildQueue() {
synchronized(queuedGuilds) {
synchronized (queuedGuilds) {
Integer guildId = queuedGuilds.poll();
if(guildId == null) return null;
if (guildId == null) {
return null;
}
wserv.removeGuildQueued(guildId);
Integer leaderId = queuedGuildLeaders.remove(guildId);
int place = 1;
for(Integer i: queuedGuilds) {
for (Integer i : queuedGuilds) {
exportMovedQueueToGuild(i, place);
place++;
}
List<Integer> list = new ArrayList<>(2);
list.add(guildId); list.add(leaderId);
list.add(guildId);
list.add(leaderId);
return list;
}
}
public boolean isQueueFull() {
synchronized(queuedGuilds) {
synchronized (queuedGuilds) {
return queuedGuilds.size() >= YamlConfig.config.server.EVENT_MAX_GUILD_QUEUE;
}
}
public int getQueueSize() {
synchronized(queuedGuilds) {
synchronized (queuedGuilds) {
return queuedGuilds.size();
}
}
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;
synchronized(queuedGuilds) {
synchronized (queuedGuilds) {
canStartAhead = queuedGuilds.isEmpty();
queuedGuilds.add(guildId);
@@ -806,9 +839,9 @@ public class EventManager {
exportMovedQueueToGuild(guildId, place);
}
if(canStartAhead) {
if(!attemptStartGuildInstance()) {
synchronized(queuedGuilds) {
if (canStartAhead) {
if (!attemptStartGuildInstance()) {
synchronized (queuedGuilds) {
queuedGuilds.add(guildId);
wserv.putGuildQueued(guildId);
queuedGuildLeaders.put(guildId, leaderId);
@@ -827,16 +860,16 @@ public class EventManager {
public boolean attemptStartGuildInstance() {
Character chr = null;
List<Integer> guildInstance = null;
while(chr == null) {
while (chr == null) {
guildInstance = getNextGuildQueue();
if(guildInstance == null) {
if (guildInstance == null) {
return false;
}
chr = cserv.getPlayerStorage().getCharacterById(guildInstance.get(1));
}
if(startInstance(chr)) {
if (startInstance(chr)) {
exportReadyGuild(guildInstance.get(0));
return true;
} else {
@@ -871,7 +904,7 @@ public class EventManager {
private EventInstanceManager getReadyInstance() {
queueLock.lock();
try {
if(readyInstances.isEmpty()) {
if (readyInstances.isEmpty()) {
fillEimQueue();
return null;
}
@@ -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,11 +25,10 @@ import client.Client;
import scripting.AbstractPlayerInteraction;
/**
*
* @author kevintjuh93
*/
public class ItemScriptMethods extends AbstractPlayerInteraction {
public ItemScriptMethods(Client c) {
super(c);
super(c);
}
}
@@ -30,9 +30,9 @@ 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) {
public MapScriptMethods(Client c) {
super(c);
}
File diff suppressed because it is too large. Load diff
@@ -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,14 +35,13 @@ import java.util.HashMap;
import java.util.Map;
/**
*
* @author RMZero213
*/
public class QuestScriptManager extends AbstractScriptManager {
private static final QuestScriptManager instance = new QuestScriptManager();
private final Map<Client, QuestActionManager> qms = new HashMap<>();
private final Map<Client, Invocable> scripts = new HashMap<>();
private final Map<Client, QuestActionManager> qms = new HashMap<>();
private final Map<Client, Invocable> scripts = new HashMap<>();
public static QuestScriptManager getInstance() {
return instance;
@@ -57,7 +56,7 @@ public class QuestScriptManager extends AbstractScriptManager {
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);
try {
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) {
Invocable iv = scripts.get(c);
if (iv != null) {
try {
c.setClickedNPC();
public void start(Client c, byte mode, byte type, int selection) {
Invocable iv = scripts.get(c);
if (iv != null) {
try {
c.setClickedNPC();
iv.invokeFunction("start", mode, type, selection);
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", e);
dispose(c);
}
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", e);
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);
if (!c.getPlayer().getQuest(quest).getStatus().equals(QuestStatus.Status.STARTED) || !c.getPlayer().getMap().containsNPC(npc)) {
dispose(c);
@@ -150,50 +149,50 @@ public class QuestScriptManager extends AbstractScriptManager {
}
}
public void end(Client c, byte mode, byte type, int selection) {
Invocable iv = scripts.get(c);
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) {
public void end(Client c, byte mode, byte type, int selection) {
Invocable iv = scripts.get(c);
if (iv != null) {
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);
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 {
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) {
qms.remove(c);
@@ -203,12 +202,12 @@ public class QuestScriptManager extends AbstractScriptManager {
c.getPlayer().flushDelayedUpdateQuests();
}
public void dispose(Client c) {
QuestActionManager qm = qms.get(c);
if (qm != null) {
dispose(qm, c);
}
}
public void dispose(Client c) {
QuestActionManager qm = qms.get(c);
if (qm != null) {
dispose(qm, c);
}
}
public QuestActionManager getQM(Client c) {
return qms.get(c);
@@ -74,11 +74,11 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
private static void sortDropEntries(List<ReactorDropEntry> from, List<ReactorDropEntry> item, List<ReactorDropEntry> visibleQuest, List<ReactorDropEntry> otherQuest, Character chr) {
ItemInformationProvider ii = ItemInformationProvider.getInstance();
for(ReactorDropEntry mde : from) {
if(!ii.isQuestItem(mde.itemId)) {
for (ReactorDropEntry mde : from) {
if (!ii.isQuestItem(mde.itemId)) {
item.add(mde);
} else {
if(chr.needQuestItem(mde.questid, mde.itemId)) {
if (chr.needQuestItem(mde.questid, mde.itemId)) {
visibleQuest.add(mde);
} else {
otherQuest.add(mde);
@@ -128,7 +128,7 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
}
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) {
@@ -144,7 +144,7 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
}
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) {
@@ -153,13 +153,17 @@ 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) {
if (!delayed) {
ItemInformationProvider ii = ItemInformationProvider.getInstance();
byte p = 1;
@@ -192,7 +196,7 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
dropPos.x -= (12 * items.size());
sprayTask = TimerManager.getInstance().register(() -> {
if(dropItems.isEmpty()) {
if (dropItems.isEmpty()) {
sprayTask.cancel(false);
return;
}
@@ -231,7 +235,7 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
items.add(new ReactorDropEntry(0, mesoChance, -1));
}
for(ReactorDropEntry mde : drops) {
for (ReactorDropEntry mde : drops) {
if (Math.random() < (dropRate / (double) mde.chance)) {
items.add(mde);
}
@@ -282,17 +286,17 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
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;
if(customTime > 0) {
if (customTime > 0) {
reactor.setDelay(customTime);
}
MapleMap map = reactor.getMap();
Monster mm = map.getMonsterById(id);
if(mm != null) {
int damage = (int)Math.ceil(mm.getMaxHp() / hitsToKill);
if (mm != null) {
int damage = (int) Math.ceil(mm.getMaxHp() / hitsToKill);
Character chr = this.getPlayer();
if(chr != null) {
if (chr != null) {
map.damageMonster(chr, mm, damage);
map.broadcastMessage(PacketCreator.damageMonster(mm.getObjectId(), damage));
}
@@ -327,7 +331,7 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
final MCSkill skil = CarnivalFactory.getInstance().getGuardian(num);
if (skil != null) {
for (Monster mons : getMap().getAllMonsters()) {
if(mons.getTeam() == team) {
if (mons.getTeam() == team) {
mons.dispelSkill(skil.getSkill());
}
}
@@ -59,9 +59,10 @@ 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) {
catch (final ScriptException | NullPointerException e) {
FilePrinter.printError(FilePrinter.REACTOR + reactor.getId() + ".txt", e);
}
}