Skip to content

Commit

Permalink
Remove unnecessary "spawn loot on animation" feature
Browse files Browse the repository at this point in the history
No longer needed since item drop timing is now dictated by the client
since two commits back.
  • Loading branch information
P0nk committed Aug 17, 2024
1 parent 2d40a89 commit 994d172
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 96 deletions.
1 change: 0 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ server:
USE_ENFORCE_MERCHANT_SAVE: true #Forces automatic DB save on merchant owners, at every item movement on shop.
USE_ENFORCE_MDOOR_POSITION: false #Forces mystic door to be spawned near spawnpoints.
USE_SPAWN_CLEAN_MDOOR: false #Makes mystic doors to be spawned without deploy animation. This clears disconnecting issues that may happen when trying to cancel doors a couple seconds after deployment.
USE_SPAWN_LOOT_ON_ANIMATION: false #Makes loot appear some time after the mob has been killed (following the mob death animation, instead of instantly).
USE_SPAWN_RELEVANT_LOOT: true #Forces to only spawn loots that are collectable by the player or any of their party members.
USE_ERASE_PERMIT_ON_OPENSHOP: true #Forces "shop permit" item to be consumed when player deploy his/her player shop.
USE_ERASE_UNTRADEABLE_DROP: true #Forces flagged untradeable items to disappear when dropped.
Expand Down
1 change: 0 additions & 1 deletion src/main/java/config/ServerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public class ServerConfig {
public boolean USE_ENFORCE_MERCHANT_SAVE;
public boolean USE_ENFORCE_MDOOR_POSITION;
public boolean USE_SPAWN_CLEAN_MDOOR;
public boolean USE_SPAWN_LOOT_ON_ANIMATION;
public boolean USE_SPAWN_RELEVANT_LOOT;
public boolean USE_ERASE_PERMIT_ON_OPENSHOP;
public boolean USE_ERASE_UNTRADEABLE_DROP;
Expand Down
111 changes: 17 additions & 94 deletions src/main/java/server/maps/MapleMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -121,7 +120,6 @@ public class MapleMap {
private final Map<String, Integer> environment = new LinkedHashMap<>();
private final Map<MapItem, Long> droppedItems = new LinkedHashMap<>();
private final LinkedList<WeakReference<MapObject>> registeredDrops = new LinkedList<>();
private final Map<MobLootEntry, Long> mobLootEntries = new HashMap(20);
private final List<Runnable> statUpdateRunnables = new ArrayList(50);
private final List<Rectangle> areas = new ArrayList<>();
private FootholdTree footholds = null;
Expand Down Expand Up @@ -160,7 +158,6 @@ public class MapleMap {
private MonsterAggroCoordinator aggroMonitor = null; // aggroMonitor activity in sync with itemMonitor
private ScheduledFuture<?> itemMonitor = null;
private ScheduledFuture<?> expireItemsTask = null;
private ScheduledFuture<?> mobSpawnLootTask = null;
private ScheduledFuture<?> characterStatUpdateTask = null;
private short itemMonitorTimeout;
private Pair<Integer, String> timeMob = null;
Expand Down Expand Up @@ -654,10 +651,10 @@ private static void sortDropEntries(List<MonsterDropEntry> from, List<MonsterDro
}
}

private byte dropItemsFromMonsterOnMap(List<MonsterDropEntry> dropEntry, Point pos, byte d, int chRate,
private byte dropItemsFromMonsterOnMap(List<MonsterDropEntry> dropEntry, Point pos, byte index, int chRate,
byte droptype, int mobpos, Character chr, Monster mob, short delay) {
if (dropEntry.isEmpty()) {
return d;
return index;
}

Collections.shuffle(dropEntry);
Expand All @@ -671,9 +668,9 @@ private byte dropItemsFromMonsterOnMap(List<MonsterDropEntry> dropEntry, Point p

if (Randomizer.nextInt(999999) < dropChance) {
if (droptype == 3) {
pos.x = mobpos + ((d % 2 == 0) ? (40 * ((d + 1) / 2)) : -(40 * (d / 2)));
pos.x = mobpos + ((index % 2 == 0) ? (40 * ((index + 1) / 2)) : -(40 * (index / 2)));
} else {
pos.x = mobpos + ((d % 2 == 0) ? (25 * ((d + 1) / 2)) : -(25 * (d / 2)));
pos.x = mobpos + ((index % 2 == 0) ? (25 * ((index + 1) / 2)) : -(25 * (index / 2)));
}
if (de.itemId == 0) { // meso
int mesos = Randomizer.nextInt(de.Maximum - de.Minimum) + de.Minimum;
Expand All @@ -698,11 +695,11 @@ private byte dropItemsFromMonsterOnMap(List<MonsterDropEntry> dropEntry, Point p
}
spawnDrop(idrop, calcDropPos(pos, mob.getPosition()), mob, chr, droptype, de.questid, delay);
}
d++;
index++;
}
}

return d;
return index;
}

private byte dropGlobalItemsFromMonsterOnMap(List<MonsterGlobalDropEntry> globalEntry, Point pos, byte d,
Expand Down Expand Up @@ -742,7 +739,6 @@ private void dropFromMonster(final Character chr, final Monster mob, final boole
final byte droptype = (byte) (mob.getStats().isExplosiveReward() ? 3 : mob.getStats().isFfaLoot() ? 2 : chr.getParty() != null ? 1 : 0);
final int mobpos = mob.getPosition().x;
int chRate = !mob.isBoss() ? chr.getDropRate() : chr.getBossDropRate();
byte d = 1;
Point pos = new Point(0, mob.getPosition().y);

MonsterStatusEffect stati = mob.getStati(MonsterStatus.SHOWDOWN);
Expand All @@ -768,8 +764,17 @@ private void dropFromMonster(final Character chr, final Monster mob, final boole
return;
}

registerMobItemDrops(droptype, mobpos, chRate, pos, dropEntry, visibleQuestEntry, otherQuestEntry, globalEntry,
chr, mob, delay);

byte index = 1;
// Normal Drops
index = dropItemsFromMonsterOnMap(dropEntry, pos, index, chRate, droptype, mobpos, chr, mob, delay);

// Global Drops
index = dropGlobalItemsFromMonsterOnMap(globalEntry, pos, index, droptype, mobpos, chr, mob, delay);

// Quest Drops
index = dropItemsFromMonsterOnMap(visibleQuestEntry, pos, index, chRate, droptype, mobpos, chr, mob, delay);
dropItemsFromMonsterOnMap(otherQuestEntry, pos, index, chRate, droptype, mobpos, chr, mob, delay);
}

public void dropItemsFromMonster(List<MonsterDropEntry> list, final Character chr, final Monster mob, short delay) {
Expand Down Expand Up @@ -802,11 +807,6 @@ private void stopItemMonitor() {
expireItemsTask.cancel(false);
expireItemsTask = null;

if (YamlConfig.config.server.USE_SPAWN_LOOT_ON_ANIMATION) {
mobSpawnLootTask.cancel(false);
mobSpawnLootTask = null;
}

characterStatUpdateTask.cancel(false);
characterStatUpdateTask = null;
}
Expand Down Expand Up @@ -863,17 +863,6 @@ private void startItemMonitor() {

expireItemsTask = TimerManager.getInstance().register(() -> makeDisappearExpiredItemDrops(), YamlConfig.config.server.ITEM_EXPIRE_CHECK, YamlConfig.config.server.ITEM_EXPIRE_CHECK);

if (YamlConfig.config.server.USE_SPAWN_LOOT_ON_ANIMATION) {
lootLock.lock();
try {
mobLootEntries.clear();
} finally {
lootLock.unlock();
}

mobSpawnLootTask = TimerManager.getInstance().register(() -> spawnMobItemDrops(), 200, 200);
}

characterStatUpdateTask = TimerManager.getInstance().register(() -> runCharacterStatUpdate(), 200, 200);

itemMonitorTimeout = 1;
Expand Down Expand Up @@ -970,67 +959,6 @@ private void makeDisappearExpiredItemDrops() {
}
}

private void registerMobItemDrops(byte droptype, int mobpos, int chRate, Point pos,
List<MonsterDropEntry> dropEntry, List<MonsterDropEntry> visibleQuestEntry,
List<MonsterDropEntry> otherQuestEntry, List<MonsterGlobalDropEntry> globalEntry,
Character chr, Monster mob, short delay) {
MobLootEntry mle = new MobLootEntry(droptype, mobpos, chRate, pos, delay, dropEntry, visibleQuestEntry,
otherQuestEntry, globalEntry, chr, mob);

if (YamlConfig.config.server.USE_SPAWN_LOOT_ON_ANIMATION) {
int animationTime = mob.getAnimationTime("die1");

lootLock.lock();
try {
long timeNow = Server.getInstance().getCurrentTime();
mobLootEntries.put(mle, timeNow + ((long) (0.42 * animationTime)));
} finally {
lootLock.unlock();
}
} else {
mle.run();
}
}

private void spawnMobItemDrops() {
Set<Entry<MobLootEntry, Long>> mleList;

lootLock.lock();
try {
mleList = new HashSet<>(mobLootEntries.entrySet());
} finally {
lootLock.unlock();
}

long timeNow = Server.getInstance().getCurrentTime();
List<MobLootEntry> toRemove = new LinkedList<>();
for (Entry<MobLootEntry, Long> mlee : mleList) {
if (mlee.getValue() < timeNow) {
toRemove.add(mlee.getKey());
}
}

if (!toRemove.isEmpty()) {
List<MobLootEntry> toSpawnLoot = new LinkedList<>();

lootLock.lock();
try {
for (MobLootEntry mle : toRemove) {
Long mler = mobLootEntries.remove(mle);
if (mler != null) {
toSpawnLoot.add(mle);
}
}
} finally {
lootLock.unlock();
}

for (MobLootEntry mle : toSpawnLoot) {
mle.run();
}
}
}

private List<MapItem> getDroppedItems() {
objectRLock.lock();
try {
Expand Down Expand Up @@ -4450,11 +4378,6 @@ public void dispose() {
expireItemsTask = null;
}

if (mobSpawnLootTask != null) {
mobSpawnLootTask.cancel(false);
mobSpawnLootTask = null;
}

if (characterStatUpdateTask != null) {
characterStatUpdateTask.cancel(false);
characterStatUpdateTask = null;
Expand Down

0 comments on commit 994d172

Please sign in to comment.