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:
@@ -26,6 +26,7 @@ import client.inventory.InventoryType;
|
||||
import client.inventory.Item;
|
||||
import client.inventory.ItemFactory;
|
||||
import client.inventory.manipulator.InventoryManipulator;
|
||||
import database.drop.DropProvider;
|
||||
import scripting.event.EventInstanceManager;
|
||||
import scripting.event.EventManager;
|
||||
import tools.DatabaseConnection;
|
||||
@@ -42,8 +43,8 @@ import java.util.List;
|
||||
* @author Ronan
|
||||
*/
|
||||
public class Marriage extends EventInstanceManager {
|
||||
public Marriage(EventManager em, String name) {
|
||||
super(em, name);
|
||||
public Marriage(EventManager em, String name, DropProvider dropProvider) {
|
||||
super(em, name, dropProvider);
|
||||
}
|
||||
|
||||
public boolean giftItemToSpouse(int cid) {
|
||||
|
||||
@@ -28,6 +28,7 @@ import client.status.MonsterStatusEffect;
|
||||
import config.YamlConfig;
|
||||
import constants.id.MobId;
|
||||
import constants.skills.*;
|
||||
import database.drop.DropProvider;
|
||||
import net.packet.Packet;
|
||||
import net.server.channel.Channel;
|
||||
import net.server.coordinator.world.MonsterAggroCoordinator;
|
||||
@@ -738,9 +739,9 @@ public class Monster extends AbstractLoadedLife {
|
||||
}
|
||||
}
|
||||
|
||||
public List<MonsterDropEntry> retrieveRelevantDrops() {
|
||||
public List<MonsterDropEntry> retrieveRelevantDrops(DropProvider dropProvider) {
|
||||
if (this.getStats().isFriendly()) { // thanks Conrad for noticing friendly mobs not spawning loots after a recent update
|
||||
return MonsterInformationProvider.getInstance().retrieveEffectiveDrop(this.getId());
|
||||
return dropProvider.getMonsterDropEntries(this.getId());
|
||||
}
|
||||
|
||||
Map<Integer, Character> pchars = map.getMapAllPlayers();
|
||||
@@ -753,7 +754,7 @@ public class Monster extends AbstractLoadedLife {
|
||||
}
|
||||
}
|
||||
|
||||
return LootManager.retrieveRelevantDrops(this.getId(), lootChars);
|
||||
return LootManager.retrieveRelevantDrops(this.getId(), lootChars, dropProvider);
|
||||
}
|
||||
|
||||
public Character killBy(final Character killer) {
|
||||
|
||||
@@ -99,34 +99,6 @@ public class MonsterInformationProvider {
|
||||
}
|
||||
}
|
||||
|
||||
public List<MonsterDropEntry> retrieveEffectiveDrop(final int monsterId) {
|
||||
return retrieveDrop(monsterId);
|
||||
}
|
||||
|
||||
private List<MonsterDropEntry> retrieveDrop(final int monsterId) {
|
||||
if (drops.containsKey(monsterId)) {
|
||||
return drops.get(monsterId);
|
||||
}
|
||||
final List<MonsterDropEntry> ret = new LinkedList<>();
|
||||
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT itemid, chance, minimum_quantity, maximum_quantity, questid FROM drop_data WHERE dropperid = ?")) {
|
||||
ps.setInt(1, monsterId);
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
ret.add(new MonsterDropEntry(rs.getInt("itemid"), rs.getInt("chance"), rs.getInt("minimum_quantity"), rs.getInt("maximum_quantity"), rs.getShort("questid")));
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return ret;
|
||||
}
|
||||
|
||||
drops.put(monsterId, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public final void setMobAttackAnimationTime(int monsterId, int attackPos, int animationTime) {
|
||||
mobAttackAnimationTime.put(new Pair<>(monsterId, attackPos), animationTime);
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
package server.loot;
|
||||
|
||||
import client.Character;
|
||||
import database.drop.DropProvider;
|
||||
import server.life.MonsterDropEntry;
|
||||
import server.life.MonsterInformationProvider;
|
||||
import server.quest.Quest;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -63,8 +63,8 @@ public class LootManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<MonsterDropEntry> retrieveRelevantDrops(int monsterId, List<Character> chrs) {
|
||||
List<MonsterDropEntry> drops = MonsterInformationProvider.getInstance().retrieveEffectiveDrop(monsterId);
|
||||
public static List<MonsterDropEntry> retrieveRelevantDrops(int monsterId, List<Character> chrs, DropProvider dropProvider) {
|
||||
List<MonsterDropEntry> drops = dropProvider.getMonsterDropEntries(monsterId);
|
||||
if (drops.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
package server.maps;
|
||||
|
||||
import constants.id.MapId;
|
||||
import database.drop.DropProvider;
|
||||
import provider.Data;
|
||||
import provider.DataProvider;
|
||||
import provider.DataProviderFactory;
|
||||
@@ -127,7 +128,8 @@ public class MapFactory {
|
||||
}
|
||||
}
|
||||
|
||||
public static MapleMap loadMapFromWz(int mapid, int world, int channel, EventInstanceManager event) {
|
||||
public static MapleMap loadMapFromWz(int mapid, int world, int channel, EventInstanceManager event,
|
||||
DropProvider dropProvider) {
|
||||
MapleMap map;
|
||||
|
||||
String mapName = getMapName(mapid);
|
||||
@@ -144,7 +146,7 @@ public class MapFactory {
|
||||
if (mobRate != null) {
|
||||
monsterRate = (Float) mobRate.getData();
|
||||
}
|
||||
map = new MapleMap(mapid, world, channel, DataTool.getInt("returnMap", infoData), monsterRate);
|
||||
map = new MapleMap(mapid, world, channel, DataTool.getInt("returnMap", infoData), monsterRate, dropProvider);
|
||||
map.setEventInstance(event);
|
||||
|
||||
String onFirstEnter = DataTool.getString(infoData.getChildByPath("onFirstUserEnter"), String.valueOf(mapid));
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
package server.maps;
|
||||
|
||||
import database.drop.DropProvider;
|
||||
import scripting.event.EventInstanceManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -30,17 +31,19 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
public class MapManager {
|
||||
private final int channel;
|
||||
private final int world;
|
||||
private EventInstanceManager event;
|
||||
private final DropProvider dropProvider;
|
||||
private EventInstanceManager eventInstanceManager;
|
||||
|
||||
private final Map<Integer, MapleMap> maps = new HashMap<>();
|
||||
|
||||
private final Lock mapsRLock;
|
||||
private final Lock mapsWLock;
|
||||
|
||||
public MapManager(EventInstanceManager eim, int world, int channel) {
|
||||
public MapManager(EventInstanceManager eim, int world, int channel, DropProvider dropProvider) {
|
||||
this.world = world;
|
||||
this.channel = channel;
|
||||
this.event = eim;
|
||||
this.eventInstanceManager = eim;
|
||||
this.dropProvider = dropProvider;
|
||||
|
||||
ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
|
||||
this.mapsRLock = readWriteLock.readLock();
|
||||
@@ -74,7 +77,7 @@ public class MapManager {
|
||||
}
|
||||
}
|
||||
|
||||
map = MapFactory.loadMapFromWz(mapid, world, channel, event);
|
||||
map = MapFactory.loadMapFromWz(mapid, world, channel, eventInstanceManager, dropProvider);
|
||||
|
||||
if (cache) {
|
||||
mapsWLock.lock();
|
||||
@@ -135,7 +138,7 @@ public class MapManager {
|
||||
map.dispose();
|
||||
}
|
||||
|
||||
this.event = null;
|
||||
this.eventInstanceManager = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import constants.game.GameConstants;
|
||||
import constants.id.MapId;
|
||||
import constants.id.MobId;
|
||||
import constants.inventory.ItemConstants;
|
||||
import database.drop.DropProvider;
|
||||
import net.packet.Packet;
|
||||
import net.server.Server;
|
||||
import net.server.channel.Channel;
|
||||
@@ -109,6 +110,7 @@ public class MapleMap {
|
||||
private final int world;
|
||||
private int seats;
|
||||
private byte monsterRate;
|
||||
private final DropProvider dropProvider;
|
||||
private boolean clock;
|
||||
private boolean boat;
|
||||
private boolean docked = false;
|
||||
@@ -168,7 +170,7 @@ public class MapleMap {
|
||||
// due to the nature of loadMapFromWz (synchronized), sole function that calls 'generateMapDropRangeCache', this lock remains optional.
|
||||
private static final Lock bndLock = new ReentrantLock(true);
|
||||
|
||||
public MapleMap(int mapid, int world, int channel, int returnMapId, float monsterRate) {
|
||||
public MapleMap(int mapid, int world, int channel, int returnMapId, float monsterRate, DropProvider dropProvider) {
|
||||
this.mapid = mapid;
|
||||
this.channel = channel;
|
||||
this.world = world;
|
||||
@@ -177,6 +179,7 @@ public class MapleMap {
|
||||
if (this.monsterRate == 0) {
|
||||
this.monsterRate = 1;
|
||||
}
|
||||
this.dropProvider = dropProvider;
|
||||
|
||||
final ReadWriteLock chrLock = new ReentrantReadWriteLock(true);
|
||||
chrRLock = chrLock.readLock();
|
||||
@@ -733,7 +736,8 @@ public class MapleMap {
|
||||
final List<MonsterDropEntry> visibleQuestEntry = new ArrayList<>();
|
||||
final List<MonsterDropEntry> otherQuestEntry = new ArrayList<>();
|
||||
|
||||
List<MonsterDropEntry> lootEntry = YamlConfig.config.server.USE_SPAWN_RELEVANT_LOOT ? mob.retrieveRelevantDrops() : mi.retrieveEffectiveDrop(mob.getId());
|
||||
List<MonsterDropEntry> lootEntry = YamlConfig.config.server.USE_SPAWN_RELEVANT_LOOT ?
|
||||
mob.retrieveRelevantDrops(dropProvider) : dropProvider.getMonsterDropEntries(mob.getId());
|
||||
sortDropEntries(lootEntry, dropEntry, visibleQuestEntry, otherQuestEntry, chr); // thanks Articuno, Limit, Rohenn for noticing quest loots not showing up in only-quest item drops scenario
|
||||
|
||||
if (lootEntry.isEmpty()) { // thanks resinate
|
||||
|
||||
Reference in New Issue
Block a user