Concurrency fix + new scripts
Fixed some situation involving concurrency upon using getCharacters() from MapleMap, added scripts and other bug fixes.
This commit is contained in:
@@ -250,19 +250,14 @@ public class MapleMonster extends AbstractLoadedMapleLife {
|
||||
|
||||
private void distributeExperienceToParty(int pid, int exp, int killer, Map<Integer, Integer> expDist) {
|
||||
LinkedList<MapleCharacter> members = new LinkedList<>();
|
||||
|
||||
map.getCharacterReadLock().lock();
|
||||
Collection<MapleCharacter> chrs = map.getCharacters();
|
||||
try {
|
||||
for (MapleCharacter mc : chrs) {
|
||||
if (mc.getPartyId() == pid) {
|
||||
members.add(mc);
|
||||
}
|
||||
|
||||
for (MapleCharacter mc : chrs) {
|
||||
if (mc.getPartyId() == pid) {
|
||||
members.add(mc);
|
||||
}
|
||||
} finally {
|
||||
map.getCharacterReadLock().unlock();
|
||||
}
|
||||
|
||||
|
||||
final int minLevel = getLevel() - 5;
|
||||
|
||||
int partyLevel = 0;
|
||||
@@ -312,29 +307,26 @@ public class MapleMonster extends AbstractLoadedMapleLife {
|
||||
for (Entry<Integer, AtomicInteger> damage : takenDamage.entrySet()) {
|
||||
expDist.put(damage.getKey(), (int) (0.80f * exp * damage.getValue().get() / totalHealth));
|
||||
}
|
||||
map.getCharacterReadLock().lock(); // avoid concurrent mod
|
||||
|
||||
Collection<MapleCharacter> chrs = map.getCharacters();
|
||||
try {
|
||||
for (MapleCharacter mc : chrs) {
|
||||
if (expDist.containsKey(mc.getId())) {
|
||||
boolean isKiller = mc.getId() == killerId;
|
||||
int xp = expDist.get(mc.getId());
|
||||
if (isKiller) {
|
||||
xp += exp / 5;
|
||||
}
|
||||
MapleParty p = mc.getParty();
|
||||
if (p != null) {
|
||||
int pID = p.getId();
|
||||
int pXP = xp + (partyExp.containsKey(pID) ? partyExp.get(pID) : 0);
|
||||
partyExp.put(pID, pXP);
|
||||
} else {
|
||||
giveExpToCharacter(mc, xp, isKiller, 1);
|
||||
}
|
||||
for (MapleCharacter mc : chrs) {
|
||||
if (expDist.containsKey(mc.getId())) {
|
||||
boolean isKiller = mc.getId() == killerId;
|
||||
int xp = expDist.get(mc.getId());
|
||||
if (isKiller) {
|
||||
xp += exp / 5;
|
||||
}
|
||||
MapleParty p = mc.getParty();
|
||||
if (p != null) {
|
||||
int pID = p.getId();
|
||||
int pXP = xp + (partyExp.containsKey(pID) ? partyExp.get(pID) : 0);
|
||||
partyExp.put(pID, pXP);
|
||||
} else {
|
||||
giveExpToCharacter(mc, xp, isKiller, 1);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
map.getCharacterReadLock().unlock();
|
||||
}
|
||||
|
||||
for (Entry<Integer, Integer> party : partyExp.entrySet()) {
|
||||
distributeExperienceToParty(party.getKey(), party.getValue(), killerId, expDist);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user