Monster drops are retrieved from DropProvider (postgres db)

This commit emphasizes the need for events to be reworked.
This is the chain of constructors the DropProvider has to pass through to reach MapleMap:
Channel -> EventScriptManager -> EventManager -> EventInstanceManager -> MapManager -> MapleMap
This commit is contained in:
P0nk
2023-03-16 08:31:38 +01:00
parent a95fa2efc1
commit cc88d382e6
12 changed files with 55 additions and 63 deletions

View File

@@ -26,6 +26,7 @@ import client.Skill;
import client.SkillFactory;
import config.YamlConfig;
import constants.inventory.ItemConstants;
import database.drop.DropProvider;
import net.server.coordinator.world.EventRecallCoordinator;
import net.server.world.Party;
import net.server.world.PartyCharacter;
@@ -110,11 +111,11 @@ public class EventInstanceManager {
// forces deletion of items not supposed to be held outside of the event, dealt on a player's leaving moment.
private final Set<Integer> exclusiveItems = new HashSet<>();
public EventInstanceManager(EventManager em, String name) {
public EventInstanceManager(EventManager em, String name, DropProvider dropProvider) {
this.em = em;
this.name = name;
this.ess = new EventScriptScheduler();
this.mapManager = new MapManager(this, em.getWorldServer().getId(), em.getChannelServer().getId());
this.mapManager = new MapManager(this, em.getWorldServer().getId(), em.getChannelServer().getId(), dropProvider);
ReadWriteLock readWriteLock = new ReentrantReadWriteLock(true);
this.readLock = readWriteLock.readLock();

View File

@@ -24,6 +24,7 @@ package scripting.event;
import client.Character;
import config.YamlConfig;
import constants.game.GameConstants;
import database.drop.DropProvider;
import net.server.Server;
import net.server.channel.Channel;
import net.server.guild.Guild;
@@ -51,7 +52,6 @@ import java.util.concurrent.locks.ReentrantLock;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
//import jdk.nashorn.api.scripting.ScriptUtils;
/**
* @author Matze
@@ -63,6 +63,7 @@ public class EventManager {
private Channel cserv;
private World wserv;
private Server server;
private final DropProvider dropProvider;
private final EventScriptScheduler ess = new EventScriptScheduler();
private final Map<String, EventInstanceManager> instances = new HashMap<>();
private final Map<String, Integer> instanceLocks = new HashMap<>();
@@ -82,12 +83,13 @@ public class EventManager {
private static final int maxLobbys = 8; // an event manager holds up to this amount of concurrent lobbys
public EventManager(Channel cserv, Invocable iv, String name) {
public EventManager(Channel cserv, Invocable iv, String name, DropProvider dropProvider) {
this.server = Server.getInstance();
this.iv = iv;
this.cserv = cserv;
this.wserv = server.getWorld(cserv.getWorld());
this.name = name;
this.dropProvider = dropProvider;
this.openedLobbys = new ArrayList<>();
for (int i = 0; i < maxLobbys; i++) {
@@ -219,7 +221,7 @@ public class EventManager {
EventInstanceManager ret = getReadyInstance();
if (ret == null) {
ret = new EventInstanceManager(this, name);
ret = new EventInstanceManager(this, name, dropProvider);
} else {
ret.setName(name);
}
@@ -235,7 +237,7 @@ public class EventManager {
}
public Marriage newMarriage(String name) throws EventInstanceInProgressException {
Marriage ret = new Marriage(this, name);
Marriage ret = new Marriage(this, name, dropProvider);
synchronized (instances) {
if (instances.containsKey(name)) {
@@ -922,7 +924,7 @@ public class EventManager {
queueLock.unlock();
}
EventInstanceManager eim = new EventInstanceManager(this, "sampleName" + nextEventId);
EventInstanceManager eim = new EventInstanceManager(this, "sampleName" + nextEventId, dropProvider);
queueLock.lock();
try {
if (this.isDisposed()) { // EM already disposed
@@ -945,4 +947,4 @@ public class EventManager {
instantiateQueuedInstance();
}
}
}
}

View File

@@ -21,6 +21,7 @@
*/
package scripting.event;
import database.drop.DropProvider;
import net.server.channel.Channel;
import org.slf4j.LoggerFactory;
import scripting.AbstractScriptManager;
@@ -42,6 +43,7 @@ public class EventScriptManager extends AbstractScriptManager {
private static final String INJECTED_VARIABLE_NAME = "em";
private static EventEntry fallback;
private final Map<String, EventEntry> events = new ConcurrentHashMap<>();
private final DropProvider dropProvider;
private boolean active = false;
private static class EventEntry {
@@ -55,7 +57,8 @@ public class EventScriptManager extends AbstractScriptManager {
public EventManager em;
}
public EventScriptManager(final Channel channel, String[] scripts) {
public EventScriptManager(final Channel channel, String[] scripts, DropProvider dropProvider) {
this.dropProvider = dropProvider;
for (String script : scripts) {
if (!script.isEmpty()) {
events.put(script, initializeEventEntry(script, channel));
@@ -106,7 +109,7 @@ public class EventScriptManager extends AbstractScriptManager {
private EventEntry initializeEventEntry(String script, Channel channel) {
ScriptEngine engine = getInvocableScriptEngine("event/" + script + ".js");
Invocable iv = SynchronizedInvocable.of((Invocable) engine);
EventManager eventManager = new EventManager(channel, iv, script);
EventManager eventManager = new EventManager(channel, iv, script, dropProvider);
engine.put(INJECTED_VARIABLE_NAME, eventManager);
return new EventEntry(iv, eventManager);
}