Rename and clean up MapleMiniDungeon
This commit is contained in:
@@ -74,7 +74,7 @@ public final class Channel {
|
||||
private final Map<Integer, Integer> storedVars = new HashMap<>();
|
||||
private Set<Integer> playersAway = new HashSet<>();
|
||||
private Map<ExpeditionType, Expedition> expeditions = new HashMap<>();
|
||||
private Map<Integer, MapleMiniDungeon> dungeons = new HashMap<>();
|
||||
private Map<Integer, MiniDungeon> dungeons = new HashMap<>();
|
||||
private List<ExpeditionType> expedType = new ArrayList<>();
|
||||
private Set<MapleMap> ownedMaps = Collections.synchronizedSet(Collections.newSetFromMap(new WeakHashMap<>()));
|
||||
private Event event;
|
||||
@@ -659,7 +659,7 @@ public final class Channel {
|
||||
if(dungeons.containsKey(dungeonid)) return false;
|
||||
|
||||
MapleMiniDungeonInfo mmdi = MapleMiniDungeonInfo.getDungeon(dungeonid);
|
||||
MapleMiniDungeon mmd = new MapleMiniDungeon(mmdi.getBase(), this.getMapFactory().getMap(mmdi.getDungeonId()).getTimeLimit()); // thanks Conrad for noticing hardcoded time limit for minidungeons
|
||||
MiniDungeon mmd = new MiniDungeon(mmdi.getBase(), this.getMapFactory().getMap(mmdi.getDungeonId()).getTimeLimit()); // thanks Conrad for noticing hardcoded time limit for minidungeons
|
||||
|
||||
dungeons.put(dungeonid, mmd);
|
||||
return true;
|
||||
@@ -668,7 +668,7 @@ public final class Channel {
|
||||
}
|
||||
}
|
||||
|
||||
public MapleMiniDungeon getMiniDungeon(int dungeonid) {
|
||||
public MiniDungeon getMiniDungeon(int dungeonid) {
|
||||
lock.lock();
|
||||
try {
|
||||
return dungeons.get(dungeonid);
|
||||
|
||||
@@ -962,7 +962,7 @@ public class World {
|
||||
|
||||
if (MapleMiniDungeonInfo.isDungeonMap(oldLeaderMapid)) {
|
||||
if (oldLeaderMapid != target.getMapId()) {
|
||||
MapleMiniDungeon mmd = mc.getClient().getChannelServer().getMiniDungeon(oldLeaderMapid);
|
||||
MiniDungeon mmd = mc.getClient().getChannelServer().getMiniDungeon(oldLeaderMapid);
|
||||
if(mmd != null) {
|
||||
mmd.close();
|
||||
}
|
||||
|
||||
@@ -2444,7 +2444,7 @@ public class MapleMap {
|
||||
}
|
||||
}, travelTime);
|
||||
} else if (MapleMiniDungeonInfo.isDungeonMap(mapid)) {
|
||||
MapleMiniDungeon mmd = chr.getClient().getChannelServer().getMiniDungeon(mapid);
|
||||
MiniDungeon mmd = chr.getClient().getChannelServer().getMiniDungeon(mapid);
|
||||
if (mmd != null) {
|
||||
mmd.registerPlayer(chr);
|
||||
}
|
||||
@@ -2682,7 +2682,7 @@ public class MapleMap {
|
||||
}
|
||||
|
||||
if (MapleMiniDungeonInfo.isDungeonMap(mapid)) {
|
||||
MapleMiniDungeon mmd = cserv.getMiniDungeon(mapid);
|
||||
MiniDungeon mmd = cserv.getMiniDungeon(mapid);
|
||||
if (mmd != null) {
|
||||
if (!mmd.unregisterPlayer(chr)) {
|
||||
cserv.removeMiniDungeon(mapid);
|
||||
|
||||
@@ -31,70 +31,73 @@ import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ronan
|
||||
*/
|
||||
public class MapleMiniDungeon {
|
||||
public class MiniDungeon {
|
||||
List<Character> players = new ArrayList<>();
|
||||
ScheduledFuture<?> timeoutTask = null;
|
||||
Lock lock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.MINIDUNGEON, true);
|
||||
|
||||
|
||||
int baseMap;
|
||||
long expireTime;
|
||||
|
||||
public MapleMiniDungeon(int base, long timeLimit) {
|
||||
|
||||
public MiniDungeon(int base, long timeLimit) {
|
||||
baseMap = base;
|
||||
expireTime = timeLimit * 1000;
|
||||
|
||||
|
||||
timeoutTask = TimerManager.getInstance().schedule(() -> close(), expireTime);
|
||||
|
||||
|
||||
expireTime += System.currentTimeMillis();
|
||||
}
|
||||
|
||||
|
||||
public boolean registerPlayer(Character chr) {
|
||||
int time = (int)((expireTime - System.currentTimeMillis()) / 1000);
|
||||
if(time > 0) chr.sendPacket(PacketCreator.getClock(time));
|
||||
|
||||
int time = (int) ((expireTime - System.currentTimeMillis()) / 1000);
|
||||
if (time > 0) {
|
||||
chr.sendPacket(PacketCreator.getClock(time));
|
||||
}
|
||||
|
||||
lock.lock();
|
||||
try {
|
||||
if(timeoutTask == null) return false;
|
||||
|
||||
if (timeoutTask == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
players.add(chr);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean unregisterPlayer(Character chr) {
|
||||
chr.sendPacket(PacketCreator.removeClock());
|
||||
|
||||
|
||||
lock.lock();
|
||||
try {
|
||||
players.remove(chr);
|
||||
|
||||
if(players.isEmpty()) {
|
||||
|
||||
if (players.isEmpty()) {
|
||||
dispose();
|
||||
return false;
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
|
||||
if (chr.isPartyLeader()) { // thanks Conrad for noticing party is not sent out of the MD as soon as leader leaves it
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void close() {
|
||||
lock.lock();
|
||||
try {
|
||||
List<Character> lchr = new ArrayList<>(players);
|
||||
|
||||
for(Character chr : lchr) {
|
||||
for (Character chr : lchr) {
|
||||
chr.changeMap(baseMap);
|
||||
}
|
||||
|
||||
@@ -104,13 +107,13 @@ public class MapleMiniDungeon {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void dispose() {
|
||||
lock.lock();
|
||||
try {
|
||||
players.clear();
|
||||
|
||||
if(timeoutTask != null) {
|
||||
|
||||
if (timeoutTask != null) {
|
||||
timeoutTask.cancel(false);
|
||||
timeoutTask = null;
|
||||
}
|
||||
Reference in New Issue
Block a user