Fix race condition when concurrently Stealing
This commit is contained in:
@@ -60,6 +60,7 @@ import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
@@ -86,7 +87,7 @@ public class Monster extends AbstractLoadedLife {
|
||||
private final Set<Integer> usedAttacks = new HashSet<>();
|
||||
private Set<Integer> calledMobOids = null;
|
||||
private WeakReference<Monster> callerMob = new WeakReference<>(null);
|
||||
private final List<Integer> stolenItems = new ArrayList<>(5);
|
||||
private final AtomicBoolean isStolen = new AtomicBoolean(false);
|
||||
private int team;
|
||||
private int parentMobOid = 0;
|
||||
private int spawnEffect = 0;
|
||||
@@ -1644,12 +1645,9 @@ public class Monster extends AbstractLoadedLife {
|
||||
return stats.getName();
|
||||
}
|
||||
|
||||
public void addStolen(int itemId) {
|
||||
stolenItems.add(itemId);
|
||||
}
|
||||
|
||||
public List<Integer> getStolen() {
|
||||
return stolenItems;
|
||||
public boolean trySteal() {
|
||||
boolean wasAlreadyStolen = this.isStolen.getAndSet(true);
|
||||
return !wasAlreadyStolen;
|
||||
}
|
||||
|
||||
public void setTempEffectiveness(Element e, ElementalEffectiveness ee, long milli) {
|
||||
@@ -2177,4 +2175,4 @@ public class Monster extends AbstractLoadedLife {
|
||||
|
||||
this.getMap().dismissRemoveAfter(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user