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:
@@ -511,7 +511,7 @@ public class MapleItemInformationProvider {
|
||||
return scrollId > 2048999 && scrollId < 2049004;
|
||||
}
|
||||
|
||||
private double testYourLuck() {
|
||||
private static double testYourLuck() {
|
||||
double result = 100.0, rolled;
|
||||
int i, j = ServerConstants.SCROLL_CHANCE_RATE;
|
||||
|
||||
@@ -524,6 +524,9 @@ public class MapleItemInformationProvider {
|
||||
return(result);
|
||||
}
|
||||
|
||||
public static boolean rollSuccessChance(double prop) {
|
||||
return(testYourLuck() <= prop && prop > 0.0);
|
||||
}
|
||||
|
||||
public Item scrollEquipWithId(Item equip, int scrollId, boolean usingWhiteScroll, boolean isGM) {
|
||||
if (equip instanceof Equip) {
|
||||
@@ -534,7 +537,7 @@ public class MapleItemInformationProvider {
|
||||
|
||||
System.out.println("GM: " + isGM + "\tWS: " + usingWhiteScroll + "\tITEM: " + scrollId);
|
||||
if (((nEquip.getUpgradeSlots() > 0 || isCleanSlate(scrollId))) || isGM) {
|
||||
if(isGM || testYourLuck() <= stats.get("success")) {
|
||||
if(isGM || rollSuccessChance((double)stats.get("success"))) {
|
||||
short flag = nEquip.getFlag();
|
||||
switch (scrollId) {
|
||||
case 2040727:
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -153,14 +153,6 @@ public class MapleMap {
|
||||
objectWLock = objectLock.writeLock();
|
||||
}
|
||||
|
||||
public ReadLock getCharacterReadLock() {
|
||||
return chrRLock;
|
||||
}
|
||||
|
||||
public WriteLock getCharacterWriteLock() {
|
||||
return chrWLock;
|
||||
}
|
||||
|
||||
public void broadcastMessage(MapleCharacter source, final byte[] packet) {
|
||||
chrRLock.lock();
|
||||
try {
|
||||
@@ -1293,9 +1285,11 @@ public class MapleMap {
|
||||
|
||||
public void addPlayer(final MapleCharacter chr) {
|
||||
chrWLock.lock();
|
||||
chrRLock.lock();
|
||||
try {
|
||||
characters.add(chr);
|
||||
} finally {
|
||||
chrRLock.unlock();
|
||||
chrWLock.unlock();
|
||||
}
|
||||
chr.setMapId(mapid);
|
||||
@@ -1534,9 +1528,11 @@ public class MapleMap {
|
||||
|
||||
public void removePlayer(MapleCharacter chr) {
|
||||
chrWLock.lock();
|
||||
chrRLock.lock();
|
||||
try {
|
||||
characters.remove(chr);
|
||||
} finally {
|
||||
chrRLock.unlock();
|
||||
chrWLock.unlock();
|
||||
}
|
||||
removeMapObject(chr.getObjectId());
|
||||
@@ -1794,7 +1790,13 @@ public class MapleMap {
|
||||
}
|
||||
|
||||
public Collection<MapleCharacter> getCharacters() {
|
||||
return Collections.unmodifiableCollection(this.characters);
|
||||
chrRLock.lock();
|
||||
try {
|
||||
return Collections.unmodifiableCollection(this.characters);
|
||||
}
|
||||
finally {
|
||||
chrRLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public MapleCharacter getCharacterById(int id) {
|
||||
@@ -2068,9 +2070,16 @@ public class MapleMap {
|
||||
}
|
||||
|
||||
public void respawn() {
|
||||
if (characters.isEmpty()) {
|
||||
return;
|
||||
chrRLock.lock();
|
||||
try {
|
||||
if (characters.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
chrRLock.unlock();
|
||||
}
|
||||
|
||||
short numShouldSpawn = (short) ((monsterSpawn.size() - spawnedMonstersOnMap.get()));//Fking lol'd
|
||||
if (numShouldSpawn > 0) {
|
||||
List<SpawnPoint> randomSpawn = new ArrayList<>(monsterSpawn);
|
||||
@@ -2227,6 +2236,7 @@ public class MapleMap {
|
||||
if (timeLimit != 0 && timeLimit < System.currentTimeMillis()) {
|
||||
warpEveryone(getForcedReturnId());
|
||||
}
|
||||
|
||||
if (getCharacters().isEmpty()) {
|
||||
resetReactors();
|
||||
killAllMonsters();
|
||||
@@ -2263,14 +2273,8 @@ public class MapleMap {
|
||||
}
|
||||
|
||||
public void warpEveryone(int to) {
|
||||
List<MapleCharacter> players;
|
||||
chrRLock.lock();
|
||||
try {
|
||||
players = new ArrayList<>(getCharacters());
|
||||
} finally {
|
||||
chrRLock.unlock();
|
||||
}
|
||||
|
||||
List<MapleCharacter> players = new ArrayList<>(getCharacters());
|
||||
|
||||
for (MapleCharacter chr : players) {
|
||||
chr.changeMap(to);
|
||||
}
|
||||
@@ -2315,7 +2319,6 @@ public class MapleMap {
|
||||
|
||||
public void warpOutByTeam(int team, int mapid) {
|
||||
List<MapleCharacter> chars = new ArrayList<>(getCharacters());
|
||||
|
||||
for (MapleCharacter chr : chars) {
|
||||
if (chr != null) {
|
||||
if (chr.getTeam() == team) {
|
||||
|
||||
Reference in New Issue
Block a user