Fix map spawn
Fix map failing to spawn in some cases.
This commit is contained in:
@@ -124,7 +124,7 @@ public class AbstractPlayerInteraction {
|
||||
return chars;
|
||||
}
|
||||
|
||||
protected MapleMap getWarpMap(int map) {
|
||||
public MapleMap getWarpMap(int map) {
|
||||
MapleMap target;
|
||||
if (getPlayer().getEventInstance() == null) {
|
||||
target = c.getChannelServer().getMapFactory().getMap(map);
|
||||
@@ -137,6 +137,10 @@ public class AbstractPlayerInteraction {
|
||||
public MapleMap getMap(int map) {
|
||||
return getWarpMap(map);
|
||||
}
|
||||
|
||||
public void resetMapObjects(int mapid) {
|
||||
getWarpMap(mapid).resetMapObjects();
|
||||
}
|
||||
|
||||
public EventManager getEventManager(String event) {
|
||||
return getClient().getEventManager(event);
|
||||
|
||||
@@ -439,14 +439,15 @@ public class MapleMonster extends AbstractLoadedMapleLife {
|
||||
eventInstance.monsterKilled(this);
|
||||
}
|
||||
}
|
||||
// idk V just a troll
|
||||
|
||||
MapleCharacter looter = map.getCharacterById(getHighestDamagerId());
|
||||
return looter != null ? looter : killer;
|
||||
}
|
||||
|
||||
public void dispatchMonsterKilled() {
|
||||
for (MonsterListener listener : listeners.toArray(new MonsterListener[listeners.size()])) {
|
||||
listener.monsterKilled(getAnimationTime("die1"));
|
||||
}
|
||||
|
||||
MapleCharacter looter = map.getCharacterById(getHighestDamagerId());
|
||||
|
||||
return looter != null ? looter : killer;
|
||||
}
|
||||
|
||||
// should only really be used to determine drop owner
|
||||
|
||||
@@ -26,7 +26,6 @@ import java.awt.Point;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class SpawnPoint {
|
||||
|
||||
private int monster, mobTime, team, fh, f;
|
||||
private Point pos;
|
||||
private long nextPossibleSpawn;
|
||||
@@ -45,9 +44,17 @@ public class SpawnPoint {
|
||||
this.mobInterval = mobInterval;
|
||||
this.nextPossibleSpawn = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public int getSpawned() {
|
||||
return spawnedMonsters.intValue();
|
||||
}
|
||||
|
||||
public void denySpawn(boolean val) {
|
||||
spawnedMonsters.set((val == false) ? 0 : 1);
|
||||
}
|
||||
|
||||
public boolean shouldSpawn() {
|
||||
if (mobTime < 0 || ((mobTime != 0 || immobile) && spawnedMonsters.get() > 0) || spawnedMonsters.get() > 2) {//lol
|
||||
if (mobTime < 0 || spawnedMonsters.get() > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -55,7 +62,7 @@ public class SpawnPoint {
|
||||
}
|
||||
|
||||
public boolean shouldForceSpawn() {
|
||||
if (mobTime < 0 || ((mobTime != 0 || immobile) && spawnedMonsters.get() > 0) || spawnedMonsters.get() > 2) {//lol
|
||||
if (mobTime < 0 || spawnedMonsters.get() > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -98,4 +105,12 @@ public class SpawnPoint {
|
||||
public final int getFh() {
|
||||
return fh;
|
||||
}
|
||||
|
||||
public int getMobTime() {
|
||||
return mobTime;
|
||||
}
|
||||
|
||||
public int getTeam() {
|
||||
return team;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +85,7 @@ public class MapleMap {
|
||||
private static final List<MapleMapObjectType> rangedMapobjectTypes = Arrays.asList(MapleMapObjectType.SHOP, MapleMapObjectType.ITEM, MapleMapObjectType.NPC, MapleMapObjectType.MONSTER, MapleMapObjectType.DOOR, MapleMapObjectType.SUMMON, MapleMapObjectType.REACTOR);
|
||||
private Map<Integer, MapleMapObject> mapobjects = new LinkedHashMap<>();
|
||||
private Collection<SpawnPoint> monsterSpawn = Collections.synchronizedList(new LinkedList<SpawnPoint>());
|
||||
private Collection<SpawnPoint> allMonsterSpawn = Collections.synchronizedList(new LinkedList<SpawnPoint>());
|
||||
private AtomicInteger spawnedMonstersOnMap = new AtomicInteger(0);
|
||||
private Collection<MapleCharacter> characters = new LinkedHashSet<>();
|
||||
private Map<Integer, MaplePortal> portals = new HashMap<>();
|
||||
@@ -672,6 +673,8 @@ public class MapleMap {
|
||||
}
|
||||
dropFromMonster(dropOwner, monster);
|
||||
}
|
||||
|
||||
monster.dispatchMonsterKilled();
|
||||
}
|
||||
|
||||
public void killFriendlies(MapleMonster mob) {
|
||||
@@ -713,20 +716,20 @@ public class MapleMap {
|
||||
if (monster.getStats().isFriendly()) {
|
||||
continue;
|
||||
}
|
||||
spawnedMonstersOnMap.decrementAndGet();
|
||||
monster.setHp(0);
|
||||
broadcastMessage(MaplePacketCreator.killMonster(monster.getObjectId(), true), monster.getPosition());
|
||||
removeMapObject(monster);
|
||||
|
||||
killMonster(monster, null, false, false, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void killAllMonsters() {
|
||||
for (SpawnPoint spawnPoint : monsterSpawn) {
|
||||
spawnPoint.denySpawn(true);
|
||||
}
|
||||
|
||||
for (MapleMapObject monstermo : getMapObjectsInRange(new Point(0, 0), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.MONSTER))) {
|
||||
MapleMonster monster = (MapleMonster) monstermo;
|
||||
spawnedMonstersOnMap.decrementAndGet();
|
||||
monster.setHp(0);
|
||||
broadcastMessage(MaplePacketCreator.killMonster(monster.getObjectId(), true), monster.getPosition());
|
||||
removeMapObject(monster);
|
||||
|
||||
killMonster(monster, null, false, false, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1032,6 +1035,7 @@ public class MapleMap {
|
||||
|
||||
public void spawnMonster(final MapleMonster monster) {
|
||||
if (mobCapacity != -1 && mobCapacity == spawnedMonstersOnMap.get()) {
|
||||
System.out.println("got here");
|
||||
return;//PyPQ
|
||||
}
|
||||
monster.setMap(this);
|
||||
@@ -1050,11 +1054,13 @@ public class MapleMap {
|
||||
}, null);
|
||||
updateMonsterController(monster);
|
||||
|
||||
if (monster.getDropPeriodTime() > 0) { //9300102 - Watchhog, 9300061 - Moon Bunny (HPQ)
|
||||
if (monster.getDropPeriodTime() > 0) { //9300102 - Watchhog, 9300061 - Moon Bunny (HPQ), 9300093 - Tylus
|
||||
if (monster.getId() == 9300102) {
|
||||
monsterItemDrop(monster, new Item(4031507, (short) 0, (short) 1), monster.getDropPeriodTime());
|
||||
} else if (monster.getId() == 9300061) {
|
||||
monsterItemDrop(monster, new Item(4001101, (short) 0, (short) 1), monster.getDropPeriodTime() / 3);
|
||||
} else if (monster.getId() == 9300093) {
|
||||
monsterItemDrop(monster, new Item(4031495, (short) 0, (short) 1), monster.getDropPeriodTime());
|
||||
} else {
|
||||
FilePrinter.printError(FilePrinter.UNHANDLED_EVENT, "UNCODED TIMED MOB DETECTED: " + monster.getId());
|
||||
}
|
||||
@@ -1782,7 +1788,13 @@ public class MapleMap {
|
||||
if (sp.shouldSpawn() || mobTime == -1) {// -1 does not respawn and should not either but force ONE spawn
|
||||
spawnMonster(sp.getMonster());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void addAllMonsterSpawn(MapleMonster monster, int mobTime, int team) {
|
||||
Point newpos = calcPointBelow(monster.getPosition());
|
||||
newpos.y -= 1;
|
||||
SpawnPoint sp = new SpawnPoint(monster, newpos, !monster.isMobile(), mobTime, mobInterval, team);
|
||||
allMonsterSpawn.add(sp);
|
||||
}
|
||||
|
||||
public Collection<MapleCharacter> getCharacters() {
|
||||
@@ -2029,6 +2041,13 @@ public class MapleMap {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void instanceMapFirstSpawn() {
|
||||
for(SpawnPoint spawnPoint: allMonsterSpawn) {
|
||||
if(spawnPoint.getMobTime() == -1) //just those allowed to be spawned only once
|
||||
spawnMonster(spawnPoint.getMonster());
|
||||
}
|
||||
}
|
||||
|
||||
public void instanceMapRespawn() {
|
||||
final int numShouldSpawn = (short) ((monsterSpawn.size() - spawnedMonstersOnMap.get()));//Fking lol'd
|
||||
@@ -2045,6 +2064,12 @@ public class MapleMap {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void restoreMapSpawnPoints() {
|
||||
for (SpawnPoint spawnPoint : monsterSpawn) {
|
||||
spawnPoint.denySpawn(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void respawn() {
|
||||
if (characters.isEmpty()) {
|
||||
@@ -2059,9 +2084,10 @@ public class MapleMap {
|
||||
if (spawnPoint.shouldSpawn()) {
|
||||
spawnMonster(spawnPoint.getMonster());
|
||||
spawned++;
|
||||
}
|
||||
if (spawned >= numShouldSpawn) {
|
||||
break;
|
||||
|
||||
if (spawned >= numShouldSpawn) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2395,4 +2421,17 @@ public class MapleMap {
|
||||
public short getMobInterval() {
|
||||
return mobInterval;
|
||||
}
|
||||
|
||||
public void clearMapObjects() {
|
||||
clearDrops();
|
||||
killAllMonsters();
|
||||
resetReactors();
|
||||
}
|
||||
|
||||
public void resetMapObjects() {
|
||||
clearMapObjects();
|
||||
|
||||
restoreMapSpawnPoints();
|
||||
instanceMapFirstSpawn();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class MapleMapFactory {
|
||||
this.world = world;
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
|
||||
public MapleMap getMap(int mapid) {
|
||||
Integer omapid = Integer.valueOf(mapid);
|
||||
MapleMap map = maps.get(omapid);
|
||||
@@ -148,6 +148,7 @@ public class MapleMapFactory {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for (MapleData life : mapData.getChildByPath("life")) {
|
||||
String id = MapleDataTool.getString(life.getChildByPath("id"));
|
||||
String type = MapleDataTool.getString(life.getChildByPath("type"));
|
||||
@@ -164,10 +165,14 @@ public class MapleMapFactory {
|
||||
} else {
|
||||
map.addMonsterSpawn(monster, mobTime, team);
|
||||
}
|
||||
|
||||
//should the map be reseted, use allMonsterSpawn list of monsters to spawn them again
|
||||
map.addAllMonsterSpawn(monster, mobTime, team);
|
||||
} else {
|
||||
map.addMapObject(myLife);
|
||||
}
|
||||
}
|
||||
|
||||
if (mapData.getChildByPath("reactor") != null) {
|
||||
for (MapleData reactor : mapData.getChildByPath("reactor")) {
|
||||
String id = MapleDataTool.getString(reactor.getChildByPath("id"));
|
||||
|
||||
Reference in New Issue
Block a user