From 8b6a2e58f8b907b01d0ecb9642a8bbbf71dc1973 Mon Sep 17 00:00:00 2001 From: P0nk Date: Thu, 9 Sep 2021 22:02:01 +0200 Subject: [PATCH] Rename and clean up MaplePlayerNPCPodium --- src/main/java/server/life/MaplePlayerNPC.java | 4 +- ...yerNPCPodium.java => PlayerNPCPodium.java} | 99 +++++++++---------- 2 files changed, 50 insertions(+), 53 deletions(-) rename src/main/java/server/life/positioner/{MaplePlayerNPCPodium.java => PlayerNPCPodium.java} (77%) diff --git a/src/main/java/server/life/MaplePlayerNPC.java b/src/main/java/server/life/MaplePlayerNPC.java index e9a7015231..f493f26118 100644 --- a/src/main/java/server/life/MaplePlayerNPC.java +++ b/src/main/java/server/life/MaplePlayerNPC.java @@ -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); } diff --git a/src/main/java/server/life/positioner/MaplePlayerNPCPodium.java b/src/main/java/server/life/positioner/PlayerNPCPodium.java similarity index 77% rename from src/main/java/server/life/positioner/MaplePlayerNPCPodium.java rename to src/main/java/server/life/positioner/PlayerNPCPodium.java index 7aa3e9c2ac..ba53741d98 100644 --- a/src/main/java/server/life/positioner/MaplePlayerNPCPodium.java +++ b/src/main/java/server/life/positioner/PlayerNPCPodium.java @@ -34,105 +34,100 @@ import java.util.Arrays; import java.util.List; /** - * * @author RonanLana - * + *

* 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 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 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 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 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); } }