Rename and clean up MaplePlayerNPCPodium

This commit is contained in:
P0nk
2021-09-09 22:02:01 +02:00
parent 14344568f2
commit 8b6a2e58f8
2 changed files with 50 additions and 53 deletions

View File

@@ -30,8 +30,8 @@ import constants.game.GameConstants;
import net.server.Server; import net.server.Server;
import net.server.channel.Channel; import net.server.channel.Channel;
import net.server.world.World; import net.server.world.World;
import server.life.positioner.MaplePlayerNPCPodium;
import server.life.positioner.MaplePlayerNPCPositioner; import server.life.positioner.MaplePlayerNPCPositioner;
import server.life.positioner.PlayerNPCPodium;
import server.maps.AbstractMapleMapObject; import server.maps.AbstractMapleMapObject;
import server.maps.MapleMap; import server.maps.MapleMap;
import server.maps.MapleMapObject; import server.maps.MapleMapObject;
@@ -389,7 +389,7 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
if (pos == null) { if (pos == null) {
if (GameConstants.isPodiumHallOfFameMap(map.getId())) { if (GameConstants.isPodiumHallOfFameMap(map.getId())) {
pos = MaplePlayerNPCPodium.getNextPlayerNpcPosition(map); pos = PlayerNPCPodium.getNextPlayerNpcPosition(map);
} else { } else {
pos = MaplePlayerNPCPositioner.getNextPlayerNpcPosition(map); pos = MaplePlayerNPCPositioner.getNextPlayerNpcPosition(map);
} }

View File

@@ -34,105 +34,100 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
*
* @author RonanLana * @author RonanLana
* * <p>
* Note: the podium uses getGroundBelow that in its turn uses inputted posY minus 7. * 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. * Podium system will implement increase-by-7 to negate that behaviour.
*/ */
public class MaplePlayerNPCPodium { public class PlayerNPCPodium {
private static int getPlatformPosX(int platform) { private static int getPlatformPosX(int platform) {
switch(platform) { return switch (platform) {
case 0: case 0 -> -50;
return -50; case 1 -> -170;
default -> 70;
case 1: };
return -170;
default:
return 70;
}
} }
private static int getPlatformPosY(int platform) { private static int getPlatformPosY(int platform) {
switch(platform) { if (platform == 0) {
case 0: return -47;
return -47;
default:
return 40;
} }
return 40;
} }
private static Point calcNextPos(int rank, int step) { private static Point calcNextPos(int rank, int step) {
int podiumPlatform = rank / step; int podiumPlatform = rank / step;
int relativePos = (rank % step) + 1; int relativePos = (rank % step) + 1;
Point pos = new Point(getPlatformPosX(podiumPlatform) + ((100 * relativePos) / (step + 1)), getPlatformPosY(podiumPlatform)); Point pos = new Point(getPlatformPosX(podiumPlatform) + ((100 * relativePos) / (step + 1)), getPlatformPosY(podiumPlatform));
return pos; return pos;
} }
private static Point rearrangePlayerNpcs(MapleMap map, int newStep, List<MaplePlayerNPC> pnpcs) { private static Point rearrangePlayerNpcs(MapleMap map, int newStep, List<MaplePlayerNPC> pnpcs) {
int i = 0; int i = 0;
for(MaplePlayerNPC pn : pnpcs) { for (MaplePlayerNPC pn : pnpcs) {
pn.updatePlayerNPCPosition(map, calcNextPos(i, newStep)); pn.updatePlayerNPCPosition(map, calcNextPos(i, newStep));
i++; i++;
} }
return calcNextPos(i, newStep); return calcNextPos(i, newStep);
} }
private static Point reorganizePlayerNpcs(MapleMap map, int newStep, List<MapleMapObject> mmoList) { private static Point reorganizePlayerNpcs(MapleMap map, int newStep, List<MapleMapObject> mmoList) {
if(!mmoList.isEmpty()) { if (!mmoList.isEmpty()) {
if(YamlConfig.config.server.USE_DEBUG) System.out.println("Reorganizing pnpc map, step " + newStep); if (YamlConfig.config.server.USE_DEBUG) {
System.out.println("Reorganizing pnpc map, step " + newStep);
}
List<MaplePlayerNPC> playerNpcs = new ArrayList<>(mmoList.size()); List<MaplePlayerNPC> playerNpcs = new ArrayList<>(mmoList.size());
for(MapleMapObject mmo : mmoList) { for (MapleMapObject mmo : mmoList) {
playerNpcs.add((MaplePlayerNPC) mmo); playerNpcs.add((MaplePlayerNPC) mmo);
} }
playerNpcs.sort((p1, p2) -> { playerNpcs.sort((p1, p2) -> {
return p1.getScriptId() - p2.getScriptId(); // scriptid as playernpc history 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()); MapleMap m = ch.getMapFactory().getMap(map.getId());
for(MaplePlayerNPC pn : playerNpcs) { for (MaplePlayerNPC pn : playerNpcs) {
m.removeMapObject(pn); m.removeMapObject(pn);
m.broadcastMessage(PacketCreator.removeNPCController(pn.getObjectId())); m.broadcastMessage(PacketCreator.removeNPCController(pn.getObjectId()));
m.broadcastMessage(PacketCreator.removePlayerNPC(pn.getObjectId())); m.broadcastMessage(PacketCreator.removePlayerNPC(pn.getObjectId()));
} }
} }
Point ret = rearrangePlayerNpcs(map, newStep, playerNpcs); 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()); MapleMap m = ch.getMapFactory().getMap(map.getId());
for(MaplePlayerNPC pn : playerNpcs) { for (MaplePlayerNPC pn : playerNpcs) {
m.addPlayerNPCMapObject(pn); m.addPlayerNPCMapObject(pn);
m.broadcastMessage(PacketCreator.spawnPlayerNPC(pn)); m.broadcastMessage(PacketCreator.spawnPlayerNPC(pn));
m.broadcastMessage(PacketCreator.getPlayerNPC(pn)); m.broadcastMessage(PacketCreator.getPlayerNPC(pn));
} }
} }
return ret; return ret;
} }
return null; return null;
} }
private static int encodePodiumData(int podiumStep, int podiumCount) { private static int encodePodiumData(int podiumStep, int podiumCount) {
return (podiumCount * (1 << 5)) + podiumStep; return (podiumCount * (1 << 5)) + podiumStep;
} }
private static Point getNextPlayerNpcPosition(MapleMap map, int podiumData) { // automated playernpc position thanks to Ronan private static Point getNextPlayerNpcPosition(MapleMap map, int podiumData) { // automated playernpc position thanks to Ronan
int podiumStep = podiumData % (1 << 5), podiumCount = (podiumData / (1 << 5)); int podiumStep = podiumData % (1 << 5), podiumCount = (podiumData / (1 << 5));
if(podiumCount >= 3 * podiumStep) { if (podiumCount >= 3 * podiumStep) {
if(podiumStep >= YamlConfig.config.server.PLAYERNPC_AREA_STEPS) return null; 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)); 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)); map.getWorldServer().setPlayerNpcMapPodiumData(map.getId(), encodePodiumData(podiumStep + 1, podiumCount + 1));
return reorganizePlayerNpcs(map, podiumStep + 1, mmoList); return reorganizePlayerNpcs(map, podiumStep + 1, mmoList);
@@ -141,11 +136,13 @@ public class MaplePlayerNPCPodium {
return calcNextPos(podiumCount, podiumStep); return calcNextPos(podiumCount, podiumStep);
} }
} }
public static Point getNextPlayerNpcPosition(MapleMap map) { public static Point getNextPlayerNpcPosition(MapleMap map) {
Point pos = getNextPlayerNpcPosition(map, map.getWorldServer().getPlayerNpcMapPodiumData(map.getId())); Point pos = getNextPlayerNpcPosition(map, map.getWorldServer().getPlayerNpcMapPodiumData(map.getId()));
if(pos == null) return null; if (pos == null) {
return null;
}
return map.getGroundBelow(pos); return map.getGroundBelow(pos);
} }
} }