Rename and clean up MaplePlayerNPCPodium
This commit is contained in:
@@ -30,8 +30,8 @@ import constants.game.GameConstants;
|
||||
import net.server.Server;
|
||||
import net.server.channel.Channel;
|
||||
import net.server.world.World;
|
||||
import server.life.positioner.MaplePlayerNPCPodium;
|
||||
import server.life.positioner.MaplePlayerNPCPositioner;
|
||||
import server.life.positioner.PlayerNPCPodium;
|
||||
import server.maps.AbstractMapleMapObject;
|
||||
import server.maps.MapleMap;
|
||||
import server.maps.MapleMapObject;
|
||||
@@ -389,7 +389,7 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
||||
|
||||
if (pos == null) {
|
||||
if (GameConstants.isPodiumHallOfFameMap(map.getId())) {
|
||||
pos = MaplePlayerNPCPodium.getNextPlayerNpcPosition(map);
|
||||
pos = PlayerNPCPodium.getNextPlayerNpcPosition(map);
|
||||
} else {
|
||||
pos = MaplePlayerNPCPositioner.getNextPlayerNpcPosition(map);
|
||||
}
|
||||
|
||||
@@ -34,105 +34,100 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author RonanLana
|
||||
*
|
||||
* <p>
|
||||
* Note: the podium uses getGroundBelow that in its turn uses inputted posY minus 7.
|
||||
* Podium system will implement increase-by-7 to negate that behaviour.
|
||||
*/
|
||||
public class MaplePlayerNPCPodium {
|
||||
public class PlayerNPCPodium {
|
||||
private static int getPlatformPosX(int platform) {
|
||||
switch(platform) {
|
||||
case 0:
|
||||
return -50;
|
||||
|
||||
case 1:
|
||||
return -170;
|
||||
|
||||
default:
|
||||
return 70;
|
||||
}
|
||||
return switch (platform) {
|
||||
case 0 -> -50;
|
||||
case 1 -> -170;
|
||||
default -> 70;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private static int getPlatformPosY(int platform) {
|
||||
switch(platform) {
|
||||
case 0:
|
||||
return -47;
|
||||
|
||||
default:
|
||||
return 40;
|
||||
if (platform == 0) {
|
||||
return -47;
|
||||
}
|
||||
return 40;
|
||||
}
|
||||
|
||||
|
||||
private static Point calcNextPos(int rank, int step) {
|
||||
int podiumPlatform = rank / step;
|
||||
int relativePos = (rank % step) + 1;
|
||||
|
||||
|
||||
Point pos = new Point(getPlatformPosX(podiumPlatform) + ((100 * relativePos) / (step + 1)), getPlatformPosY(podiumPlatform));
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
private static Point rearrangePlayerNpcs(MapleMap map, int newStep, List<MaplePlayerNPC> pnpcs) {
|
||||
int i = 0;
|
||||
for(MaplePlayerNPC pn : pnpcs) {
|
||||
for (MaplePlayerNPC pn : pnpcs) {
|
||||
pn.updatePlayerNPCPosition(map, calcNextPos(i, newStep));
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
return calcNextPos(i, newStep);
|
||||
}
|
||||
|
||||
|
||||
private static Point reorganizePlayerNpcs(MapleMap map, int newStep, List<MapleMapObject> mmoList) {
|
||||
if(!mmoList.isEmpty()) {
|
||||
if(YamlConfig.config.server.USE_DEBUG) System.out.println("Reorganizing pnpc map, step " + newStep);
|
||||
|
||||
if (!mmoList.isEmpty()) {
|
||||
if (YamlConfig.config.server.USE_DEBUG) {
|
||||
System.out.println("Reorganizing pnpc map, step " + newStep);
|
||||
}
|
||||
|
||||
List<MaplePlayerNPC> playerNpcs = new ArrayList<>(mmoList.size());
|
||||
for(MapleMapObject mmo : mmoList) {
|
||||
for (MapleMapObject mmo : mmoList) {
|
||||
playerNpcs.add((MaplePlayerNPC) mmo);
|
||||
}
|
||||
|
||||
|
||||
playerNpcs.sort((p1, p2) -> {
|
||||
return p1.getScriptId() - p2.getScriptId(); // scriptid as playernpc history
|
||||
});
|
||||
|
||||
for(Channel ch : Server.getInstance().getChannelsFromWorld(map.getWorld())) {
|
||||
|
||||
for (Channel ch : Server.getInstance().getChannelsFromWorld(map.getWorld())) {
|
||||
MapleMap m = ch.getMapFactory().getMap(map.getId());
|
||||
|
||||
for(MaplePlayerNPC pn : playerNpcs) {
|
||||
|
||||
for (MaplePlayerNPC pn : playerNpcs) {
|
||||
m.removeMapObject(pn);
|
||||
m.broadcastMessage(PacketCreator.removeNPCController(pn.getObjectId()));
|
||||
m.broadcastMessage(PacketCreator.removePlayerNPC(pn.getObjectId()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Point ret = rearrangePlayerNpcs(map, newStep, playerNpcs);
|
||||
|
||||
for(Channel ch : Server.getInstance().getChannelsFromWorld(map.getWorld())) {
|
||||
|
||||
for (Channel ch : Server.getInstance().getChannelsFromWorld(map.getWorld())) {
|
||||
MapleMap m = ch.getMapFactory().getMap(map.getId());
|
||||
|
||||
for(MaplePlayerNPC pn : playerNpcs) {
|
||||
|
||||
for (MaplePlayerNPC pn : playerNpcs) {
|
||||
m.addPlayerNPCMapObject(pn);
|
||||
m.broadcastMessage(PacketCreator.spawnPlayerNPC(pn));
|
||||
m.broadcastMessage(PacketCreator.getPlayerNPC(pn));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static int encodePodiumData(int podiumStep, int podiumCount) {
|
||||
return (podiumCount * (1 << 5)) + podiumStep;
|
||||
}
|
||||
|
||||
|
||||
private static Point getNextPlayerNpcPosition(MapleMap map, int podiumData) { // automated playernpc position thanks to Ronan
|
||||
int podiumStep = podiumData % (1 << 5), podiumCount = (podiumData / (1 << 5));
|
||||
|
||||
if(podiumCount >= 3 * podiumStep) {
|
||||
if(podiumStep >= YamlConfig.config.server.PLAYERNPC_AREA_STEPS) return null;
|
||||
|
||||
|
||||
if (podiumCount >= 3 * podiumStep) {
|
||||
if (podiumStep >= YamlConfig.config.server.PLAYERNPC_AREA_STEPS) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<MapleMapObject> mmoList = map.getMapObjectsInRange(new Point(0, 0), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.PLAYER_NPC));
|
||||
map.getWorldServer().setPlayerNpcMapPodiumData(map.getId(), encodePodiumData(podiumStep + 1, podiumCount + 1));
|
||||
return reorganizePlayerNpcs(map, podiumStep + 1, mmoList);
|
||||
@@ -141,11 +136,13 @@ public class MaplePlayerNPCPodium {
|
||||
return calcNextPos(podiumCount, podiumStep);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Point getNextPlayerNpcPosition(MapleMap map) {
|
||||
Point pos = getNextPlayerNpcPosition(map, map.getWorldServer().getPlayerNpcMapPodiumData(map.getId()));
|
||||
if(pos == null) return null;
|
||||
|
||||
if (pos == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return map.getGroundBelow(pos);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user