Rename and clean up MaplePlayerNPCPositioner
This commit is contained in:
@@ -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.MaplePlayerNPCPositioner;
|
|
||||||
import server.life.positioner.PlayerNPCPodium;
|
import server.life.positioner.PlayerNPCPodium;
|
||||||
|
import server.life.positioner.PlayerNPCPositioner;
|
||||||
import server.maps.AbstractMapleMapObject;
|
import server.maps.AbstractMapleMapObject;
|
||||||
import server.maps.MapleMap;
|
import server.maps.MapleMap;
|
||||||
import server.maps.MapleMapObject;
|
import server.maps.MapleMapObject;
|
||||||
@@ -391,7 +391,7 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
|||||||
if (GameConstants.isPodiumHallOfFameMap(map.getId())) {
|
if (GameConstants.isPodiumHallOfFameMap(map.getId())) {
|
||||||
pos = PlayerNPCPodium.getNextPlayerNpcPosition(map);
|
pos = PlayerNPCPodium.getNextPlayerNpcPosition(map);
|
||||||
} else {
|
} else {
|
||||||
pos = MaplePlayerNPCPositioner.getNextPlayerNpcPosition(map);
|
pos = PlayerNPCPositioner.getNextPlayerNpcPosition(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos == null) {
|
if (pos == null) {
|
||||||
|
|||||||
@@ -35,20 +35,18 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author RonanLana
|
* @author RonanLana
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class MaplePlayerNPCPositioner {
|
public class PlayerNPCPositioner {
|
||||||
|
|
||||||
private static boolean isPlayerNpcNearby(List<Point> otherPos, Point searchPos, int xLimit, int yLimit) {
|
private static boolean isPlayerNpcNearby(List<Point> otherPos, Point searchPos, int xLimit, int yLimit) {
|
||||||
int xLimit2 = xLimit / 2, yLimit2 = yLimit / 2;
|
int xLimit2 = xLimit / 2, yLimit2 = yLimit / 2;
|
||||||
|
|
||||||
Rectangle searchRect = new Rectangle(searchPos.x - xLimit2, searchPos.y - yLimit2, xLimit, yLimit);
|
Rectangle searchRect = new Rectangle(searchPos.x - xLimit2, searchPos.y - yLimit2, xLimit, yLimit);
|
||||||
for(Point pos : otherPos) {
|
for (Point pos : otherPos) {
|
||||||
Rectangle otherRect = new Rectangle(pos.x - xLimit2, pos.y - yLimit2, xLimit, yLimit);
|
Rectangle otherRect = new Rectangle(pos.x - xLimit2, pos.y - yLimit2, xLimit, yLimit);
|
||||||
|
|
||||||
if(otherRect.intersects(searchRect)) {
|
if (otherRect.intersects(searchRect)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,16 +70,16 @@ public class MaplePlayerNPCPositioner {
|
|||||||
int cx = calcDx(newStep), cy = calcDy(newStep);
|
int cx = calcDx(newStep), cy = calcDy(newStep);
|
||||||
|
|
||||||
List<Point> otherPlayerNpcs = new LinkedList<>();
|
List<Point> otherPlayerNpcs = new LinkedList<>();
|
||||||
while(py < outy) {
|
while (py < outy) {
|
||||||
px = leftPx;
|
px = leftPx;
|
||||||
|
|
||||||
while(px < outx) {
|
while (px < outx) {
|
||||||
Point searchPos = map.getPointBelow(new Point(px, py));
|
Point searchPos = map.getPointBelow(new Point(px, py));
|
||||||
if(searchPos != null) {
|
if (searchPos != null) {
|
||||||
if(!isPlayerNpcNearby(otherPlayerNpcs, searchPos, cx, cy)) {
|
if (!isPlayerNpcNearby(otherPlayerNpcs, searchPos, cx, cy)) {
|
||||||
otherPlayerNpcs.add(searchPos);
|
otherPlayerNpcs.add(searchPos);
|
||||||
|
|
||||||
if(otherPlayerNpcs.size() == pnpcsSize) {
|
if (otherPlayerNpcs.size() == pnpcsSize) {
|
||||||
return otherPlayerNpcs;
|
return otherPlayerNpcs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -106,14 +104,14 @@ public class MaplePlayerNPCPositioner {
|
|||||||
List<Point> otherPlayerNpcs = new LinkedList<>();
|
List<Point> otherPlayerNpcs = new LinkedList<>();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while(py < outy) {
|
while (py < outy) {
|
||||||
px = leftPx;
|
px = leftPx;
|
||||||
|
|
||||||
while(px < outx) {
|
while (px < outx) {
|
||||||
Point searchPos = map.getPointBelow(new Point(px, py));
|
Point searchPos = map.getPointBelow(new Point(px, py));
|
||||||
if(searchPos != null) {
|
if (searchPos != null) {
|
||||||
if(!isPlayerNpcNearby(otherPlayerNpcs, searchPos, cx, cy)) {
|
if (!isPlayerNpcNearby(otherPlayerNpcs, searchPos, cx, cy)) {
|
||||||
if(i == pnpcs.size()) {
|
if (i == pnpcs.size()) {
|
||||||
return searchPos;
|
return searchPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,11 +133,13 @@ public class MaplePlayerNPCPositioner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,10 +147,10 @@ public class MaplePlayerNPCPositioner {
|
|||||||
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()));
|
||||||
@@ -159,10 +159,10 @@ public class MaplePlayerNPCPositioner {
|
|||||||
|
|
||||||
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));
|
||||||
@@ -178,7 +178,7 @@ public class MaplePlayerNPCPositioner {
|
|||||||
private static Point getNextPlayerNpcPosition(MapleMap map, int initStep) { // automated playernpc position thanks to Ronan
|
private static Point getNextPlayerNpcPosition(MapleMap map, int initStep) { // automated playernpc position thanks to Ronan
|
||||||
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));
|
||||||
List<Point> otherPlayerNpcs = new LinkedList<>();
|
List<Point> otherPlayerNpcs = new LinkedList<>();
|
||||||
for(MapleMapObject mmo : mmoList) {
|
for (MapleMapObject mmo : mmoList) {
|
||||||
otherPlayerNpcs.add(mmo.getPosition());
|
otherPlayerNpcs.add(mmo.getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,21 +188,21 @@ public class MaplePlayerNPCPositioner {
|
|||||||
boolean reorganize = false;
|
boolean reorganize = false;
|
||||||
|
|
||||||
int i = initStep;
|
int i = initStep;
|
||||||
while(i < YamlConfig.config.server.PLAYERNPC_AREA_STEPS) {
|
while (i < YamlConfig.config.server.PLAYERNPC_AREA_STEPS) {
|
||||||
int leftPx = mapArea.x + YamlConfig.config.server.PLAYERNPC_INITIAL_X, px, py = mapArea.y + YamlConfig.config.server.PLAYERNPC_INITIAL_Y;
|
int leftPx = mapArea.x + YamlConfig.config.server.PLAYERNPC_INITIAL_X, px, py = mapArea.y + YamlConfig.config.server.PLAYERNPC_INITIAL_Y;
|
||||||
|
|
||||||
while(py < outy) {
|
while (py < outy) {
|
||||||
px = leftPx;
|
px = leftPx;
|
||||||
|
|
||||||
while(px < outx) {
|
while (px < outx) {
|
||||||
Point searchPos = map.getPointBelow(new Point(px, py));
|
Point searchPos = map.getPointBelow(new Point(px, py));
|
||||||
if(searchPos != null) {
|
if (searchPos != null) {
|
||||||
if(!isPlayerNpcNearby(otherPlayerNpcs, searchPos, cx, cy)) {
|
if (!isPlayerNpcNearby(otherPlayerNpcs, searchPos, cx, cy)) {
|
||||||
if(i > initStep) {
|
if (i > initStep) {
|
||||||
map.getWorldServer().setPlayerNpcMapStep(map.getId(), i);
|
map.getWorldServer().setPlayerNpcMapStep(map.getId(), i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(reorganize && YamlConfig.config.server.PLAYERNPC_ORGANIZE_AREA) {
|
if (reorganize && YamlConfig.config.server.PLAYERNPC_ORGANIZE_AREA) {
|
||||||
return reorganizePlayerNpcs(map, i, mmoList);
|
return reorganizePlayerNpcs(map, i, mmoList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,12 +221,12 @@ public class MaplePlayerNPCPositioner {
|
|||||||
|
|
||||||
cx = calcDx(i);
|
cx = calcDx(i);
|
||||||
cy = calcDy(i);
|
cy = calcDy(i);
|
||||||
if(YamlConfig.config.server.PLAYERNPC_ORGANIZE_AREA) {
|
if (YamlConfig.config.server.PLAYERNPC_ORGANIZE_AREA) {
|
||||||
otherPlayerNpcs = rearrangePlayerNpcPositions(map, i, mmoList.size());
|
otherPlayerNpcs = rearrangePlayerNpcPositions(map, i, mmoList.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(i > initStep) {
|
if (i > initStep) {
|
||||||
map.getWorldServer().setPlayerNpcMapStep(map.getId(), YamlConfig.config.server.PLAYERNPC_AREA_STEPS - 1);
|
map.getWorldServer().setPlayerNpcMapStep(map.getId(), YamlConfig.config.server.PLAYERNPC_AREA_STEPS - 1);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
Reference in New Issue
Block a user