Rename and clean up MaplePlayerNPC
This commit is contained in:
@@ -39,7 +39,7 @@ public class MaplePlayerNPCFactory {
|
||||
|
||||
private static DataProvider npcData = DataProviderFactory.getDataProvider(WZFiles.NPC);
|
||||
|
||||
private static final Map<Integer, List<MaplePlayerNPC>> dnpcMaps = new HashMap<>();
|
||||
private static final Map<Integer, List<PlayerNPC>> dnpcMaps = new HashMap<>();
|
||||
private static Integer runningDeveloperOid = 2147483000; // 647 slots, long enough
|
||||
|
||||
public synchronized static boolean isExistentScriptid(int scriptid) {
|
||||
@@ -97,13 +97,13 @@ public class MaplePlayerNPCFactory {
|
||||
equips.put(equippos, equipid);
|
||||
}
|
||||
|
||||
List<MaplePlayerNPC> dnpcSet = dnpcMaps.get(mapid);
|
||||
List<PlayerNPC> dnpcSet = dnpcMaps.get(mapid);
|
||||
if(dnpcSet == null) {
|
||||
dnpcSet = new LinkedList<>();
|
||||
dnpcMaps.put(mapid, dnpcSet);
|
||||
}
|
||||
|
||||
dnpcSet.add(new MaplePlayerNPC(name, scriptId, face, hair, gender, skin, equips, dir, FH, RX0, RX1, CX, CY, runningDeveloperOid));
|
||||
dnpcSet.add(new PlayerNPC(name, scriptId, face, hair, gender, skin, equips, dir, FH, RX0, RX1, CX, CY, runningDeveloperOid));
|
||||
runningDeveloperOid++;
|
||||
}
|
||||
} else {
|
||||
@@ -123,19 +123,19 @@ public class MaplePlayerNPCFactory {
|
||||
equips.put((short) -7, 1072154);
|
||||
equips.put((short) -5, 1040103);
|
||||
|
||||
List<MaplePlayerNPC> dnpcSet = dnpcMaps.get(mapid);
|
||||
List<PlayerNPC> dnpcSet = dnpcMaps.get(mapid);
|
||||
if(dnpcSet == null) {
|
||||
dnpcSet = new LinkedList<>();
|
||||
dnpcMaps.put(mapid, dnpcSet);
|
||||
}
|
||||
|
||||
dnpcSet.add(new MaplePlayerNPC(name, scriptId, face, hair, gender, (byte) skin, equips, dir, FH, RX0, RX1, CX, CY, runningDeveloperOid));
|
||||
dnpcSet.add(new PlayerNPC(name, scriptId, face, hair, gender, (byte) skin, equips, dir, FH, RX0, RX1, CX, CY, runningDeveloperOid));
|
||||
runningDeveloperOid++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized static List<MaplePlayerNPC> getDeveloperNpcsFromMapid(int mapid) {
|
||||
public synchronized static List<PlayerNPC> getDeveloperNpcsFromMapid(int mapid) {
|
||||
return dnpcMaps.get(mapid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,11 +47,10 @@ import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author XoticStory
|
||||
* @author Ronan
|
||||
*/
|
||||
public class MaplePlayerNPC extends AbstractMapleMapObject {
|
||||
public class PlayerNPC extends AbstractMapleMapObject {
|
||||
private static final Map<Byte, List<Integer>> availablePlayerNpcScriptIds = new HashMap<>();
|
||||
private static final AtomicInteger runningOverallRank = new AtomicInteger();
|
||||
private static final List<AtomicInteger> runningWorldRank = new ArrayList<>();
|
||||
@@ -68,7 +67,7 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
||||
getRunningMetadata();
|
||||
}
|
||||
|
||||
public MaplePlayerNPC(String name, int scriptId, int face, int hair, int gender, byte skin, Map<Short, Integer> equips, int dir, int FH, int RX0, int RX1, int CX, int CY, int oid) {
|
||||
public PlayerNPC(String name, int scriptId, int face, int hair, int gender, byte skin, Map<Short, Integer> equips, int dir, int FH, int RX0, int RX1, int CX, int CY, int oid) {
|
||||
this.equips = equips;
|
||||
this.scriptId = scriptId;
|
||||
this.face = face;
|
||||
@@ -87,7 +86,7 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
||||
setObjectId(oid);
|
||||
}
|
||||
|
||||
public MaplePlayerNPC(ResultSet rs) {
|
||||
public PlayerNPC(ResultSet rs) {
|
||||
try {
|
||||
CY = rs.getInt("cy");
|
||||
name = rs.getString("name");
|
||||
@@ -261,7 +260,7 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
||||
|
||||
private static int getAndIncrementRunningWorldJobRanks(int world, int job) {
|
||||
AtomicInteger wjr = runningWorldJobRank.get(new Pair<>(world, job));
|
||||
if(wjr == null) {
|
||||
if (wjr == null) {
|
||||
wjr = new AtomicInteger(1);
|
||||
runningWorldJobRank.put(new Pair<>(world, job), wjr);
|
||||
}
|
||||
@@ -357,15 +356,15 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
||||
private static int getNextScriptId(byte branch) {
|
||||
List<Integer> availablesBranch = availablePlayerNpcScriptIds.get(branch);
|
||||
|
||||
if(availablesBranch == null) {
|
||||
if (availablesBranch == null) {
|
||||
availablesBranch = new ArrayList<>(20);
|
||||
availablePlayerNpcScriptIds.put(branch, availablesBranch);
|
||||
}
|
||||
|
||||
if(availablesBranch.isEmpty()) {
|
||||
if (availablesBranch.isEmpty()) {
|
||||
fetchAvailableScriptIdsFromDb(branch, availablesBranch);
|
||||
|
||||
if(availablesBranch.isEmpty()) {
|
||||
if (availablesBranch.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -373,7 +372,7 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
||||
return availablesBranch.remove(availablesBranch.size() - 1);
|
||||
}
|
||||
|
||||
private static MaplePlayerNPC createPlayerNPCInternal(MapleMap map, Point pos, Character chr) {
|
||||
private static PlayerNPC createPlayerNPCInternal(MapleMap map, Point pos, Character chr) {
|
||||
int mapId = map.getId();
|
||||
|
||||
if (!canSpawnPlayerNpc(chr.getName(), mapId)) {
|
||||
@@ -406,7 +405,7 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
||||
int worldId = chr.getWorld();
|
||||
int jobId = (chr.getJob().getId() / 100) * 100;
|
||||
|
||||
MaplePlayerNPC ret;
|
||||
PlayerNPC ret;
|
||||
try (Connection con = DatabaseConnection.getConnection()) {
|
||||
boolean createNew = false;
|
||||
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM playernpcs WHERE scriptid = ?")) {
|
||||
@@ -467,7 +466,7 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
rs.next();
|
||||
ret = new MaplePlayerNPC(rs);
|
||||
ret = new PlayerNPC(rs);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -519,8 +518,8 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
||||
return mapids;
|
||||
}
|
||||
|
||||
private static synchronized Pair<MaplePlayerNPC, List<Integer>> processPlayerNPCInternal(MapleMap map, Point pos, Character chr, boolean create) {
|
||||
if(create) {
|
||||
private static synchronized Pair<PlayerNPC, List<Integer>> processPlayerNPCInternal(MapleMap map, Point pos, Character chr, boolean create) {
|
||||
if (create) {
|
||||
return new Pair<>(createPlayerNPCInternal(map, pos, chr), null);
|
||||
} else {
|
||||
return new Pair<>(null, removePlayerNPCInternal(map, chr));
|
||||
@@ -532,10 +531,12 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
||||
}
|
||||
|
||||
public static boolean spawnPlayerNPC(int mapid, Point pos, Character chr) {
|
||||
if(chr == null) return false;
|
||||
if (chr == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MaplePlayerNPC pn = processPlayerNPCInternal(chr.getClient().getChannelServer().getMapFactory().getMap(mapid), pos, chr, true).getLeft();
|
||||
if(pn != null) {
|
||||
PlayerNPC pn = processPlayerNPCInternal(chr.getClient().getChannelServer().getMapFactory().getMap(mapid), pos, chr, true).getLeft();
|
||||
if (pn != null) {
|
||||
for (Channel channel : Server.getInstance().getChannelsFromWorld(chr.getWorld())) {
|
||||
MapleMap m = channel.getMapFactory().getMap(mapid);
|
||||
|
||||
@@ -550,12 +551,12 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
||||
}
|
||||
}
|
||||
|
||||
private static MaplePlayerNPC getPlayerNPCFromWorldMap(String name, int world, int map) {
|
||||
private static PlayerNPC getPlayerNPCFromWorldMap(String name, int world, int map) {
|
||||
World wserv = Server.getInstance().getWorld(world);
|
||||
for(MapleMapObject pnpcObj : wserv.getChannel(1).getMapFactory().getMap(map).getMapObjectsInRange(new Point(0, 0), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.PLAYER_NPC))) {
|
||||
MaplePlayerNPC pn = (MaplePlayerNPC) pnpcObj;
|
||||
for (MapleMapObject pnpcObj : wserv.getChannel(1).getMapFactory().getMap(map).getMapObjectsInRange(new Point(0, 0), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.PLAYER_NPC))) {
|
||||
PlayerNPC pn = (PlayerNPC) pnpcObj;
|
||||
|
||||
if(name.contentEquals(pn.getName()) && pn.getScriptId() < 9977777) {
|
||||
if (name.contentEquals(pn.getName()) && pn.getScriptId() < 9977777) {
|
||||
return pn;
|
||||
}
|
||||
}
|
||||
@@ -564,15 +565,17 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
||||
}
|
||||
|
||||
public static void removePlayerNPC(Character chr) {
|
||||
if(chr == null) return;
|
||||
if (chr == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Integer> updateMapids = processPlayerNPCInternal(null, null, chr, false).getRight();
|
||||
int worldid = updateMapids.remove(0);
|
||||
|
||||
for (Integer mapid : updateMapids) {
|
||||
MaplePlayerNPC pn = getPlayerNPCFromWorldMap(chr.getName(), worldid, mapid);
|
||||
PlayerNPC pn = getPlayerNPCFromWorldMap(chr.getName(), worldid, mapid);
|
||||
|
||||
if(pn != null) {
|
||||
if (pn != null) {
|
||||
for (Channel channel : Server.getInstance().getChannelsFromWorld(worldid)) {
|
||||
MapleMap m = channel.getMapFactory().getMap(mapid);
|
||||
m.removeMapObject(pn);
|
||||
@@ -586,13 +589,15 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
||||
|
||||
public static void multicastSpawnPlayerNPC(int mapid, int world) {
|
||||
World wserv = Server.getInstance().getWorld(world);
|
||||
if (wserv == null) return;
|
||||
if (wserv == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Client c = Client.createMock();
|
||||
c.setWorld(world);
|
||||
c.setChannel(1);
|
||||
|
||||
for(Character mc : wserv.loadAndGetAllCharactersView()) {
|
||||
for (Character mc : wserv.loadAndGetAllCharactersView()) {
|
||||
mc.setClient(c);
|
||||
spawnPlayerNPC(mapid, mc);
|
||||
}
|
||||
@@ -613,7 +618,7 @@ public class MaplePlayerNPC extends AbstractMapleMapObject {
|
||||
MapleMap m = channel.getMapFactory().getMap(map);
|
||||
|
||||
for (MapleMapObject pnpcObj : m.getMapObjectsInRange(new Point(0, 0), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.PLAYER_NPC))) {
|
||||
MaplePlayerNPC pn = (MaplePlayerNPC) pnpcObj;
|
||||
PlayerNPC pn = (PlayerNPC) pnpcObj;
|
||||
m.removeMapObject(pnpcObj);
|
||||
m.broadcastMessage(PacketCreator.removeNPCController(pn.getObjectId()));
|
||||
m.broadcastMessage(PacketCreator.removePlayerNPC(pn.getObjectId()));
|
||||
@@ -22,7 +22,7 @@ package server.life.positioner;
|
||||
import config.YamlConfig;
|
||||
import net.server.Server;
|
||||
import net.server.channel.Channel;
|
||||
import server.life.MaplePlayerNPC;
|
||||
import server.life.PlayerNPC;
|
||||
import server.maps.MapleMap;
|
||||
import server.maps.MapleMapObject;
|
||||
import server.maps.MapleMapObjectType;
|
||||
@@ -63,9 +63,9 @@ public class PlayerNPCPodium {
|
||||
return pos;
|
||||
}
|
||||
|
||||
private static Point rearrangePlayerNpcs(MapleMap map, int newStep, List<MaplePlayerNPC> pnpcs) {
|
||||
private static Point rearrangePlayerNpcs(MapleMap map, int newStep, List<PlayerNPC> pnpcs) {
|
||||
int i = 0;
|
||||
for (MaplePlayerNPC pn : pnpcs) {
|
||||
for (PlayerNPC pn : pnpcs) {
|
||||
pn.updatePlayerNPCPosition(map, calcNextPos(i, newStep));
|
||||
i++;
|
||||
}
|
||||
@@ -79,9 +79,9 @@ public class PlayerNPCPodium {
|
||||
System.out.println("Reorganizing pnpc map, step " + newStep);
|
||||
}
|
||||
|
||||
List<MaplePlayerNPC> playerNpcs = new ArrayList<>(mmoList.size());
|
||||
List<PlayerNPC> playerNpcs = new ArrayList<>(mmoList.size());
|
||||
for (MapleMapObject mmo : mmoList) {
|
||||
playerNpcs.add((MaplePlayerNPC) mmo);
|
||||
playerNpcs.add((PlayerNPC) mmo);
|
||||
}
|
||||
|
||||
playerNpcs.sort((p1, p2) -> {
|
||||
@@ -91,7 +91,7 @@ public class PlayerNPCPodium {
|
||||
for (Channel ch : Server.getInstance().getChannelsFromWorld(map.getWorld())) {
|
||||
MapleMap m = ch.getMapFactory().getMap(map.getId());
|
||||
|
||||
for (MaplePlayerNPC pn : playerNpcs) {
|
||||
for (PlayerNPC pn : playerNpcs) {
|
||||
m.removeMapObject(pn);
|
||||
m.broadcastMessage(PacketCreator.removeNPCController(pn.getObjectId()));
|
||||
m.broadcastMessage(PacketCreator.removePlayerNPC(pn.getObjectId()));
|
||||
@@ -103,7 +103,7 @@ public class PlayerNPCPodium {
|
||||
for (Channel ch : Server.getInstance().getChannelsFromWorld(map.getWorld())) {
|
||||
MapleMap m = ch.getMapFactory().getMap(map.getId());
|
||||
|
||||
for (MaplePlayerNPC pn : playerNpcs) {
|
||||
for (PlayerNPC pn : playerNpcs) {
|
||||
m.addPlayerNPCMapObject(pn);
|
||||
m.broadcastMessage(PacketCreator.spawnPlayerNPC(pn));
|
||||
m.broadcastMessage(PacketCreator.getPlayerNPC(pn));
|
||||
|
||||
@@ -22,7 +22,7 @@ package server.life.positioner;
|
||||
import config.YamlConfig;
|
||||
import net.server.Server;
|
||||
import net.server.channel.Channel;
|
||||
import server.life.MaplePlayerNPC;
|
||||
import server.life.PlayerNPC;
|
||||
import server.maps.MapleMap;
|
||||
import server.maps.MapleMapObject;
|
||||
import server.maps.MapleMapObjectType;
|
||||
@@ -94,7 +94,7 @@ public class PlayerNPCPositioner {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Point rearrangePlayerNpcs(MapleMap map, int newStep, List<MaplePlayerNPC> pnpcs) {
|
||||
private static Point rearrangePlayerNpcs(MapleMap map, int newStep, List<PlayerNPC> pnpcs) {
|
||||
Rectangle mapArea = map.getMapArea();
|
||||
|
||||
int leftPx = mapArea.x + YamlConfig.config.server.PLAYERNPC_INITIAL_X, px, py = mapArea.y + YamlConfig.config.server.PLAYERNPC_INITIAL_Y;
|
||||
@@ -115,7 +115,7 @@ public class PlayerNPCPositioner {
|
||||
return searchPos;
|
||||
}
|
||||
|
||||
MaplePlayerNPC pn = pnpcs.get(i);
|
||||
PlayerNPC pn = pnpcs.get(i);
|
||||
i++;
|
||||
|
||||
pn.updatePlayerNPCPosition(map, searchPos);
|
||||
@@ -138,9 +138,9 @@ public class PlayerNPCPositioner {
|
||||
System.out.println("Reorganizing pnpc map, step " + newStep);
|
||||
}
|
||||
|
||||
List<MaplePlayerNPC> playerNpcs = new ArrayList<>(mmoList.size());
|
||||
List<PlayerNPC> playerNpcs = new ArrayList<>(mmoList.size());
|
||||
for (MapleMapObject mmo : mmoList) {
|
||||
playerNpcs.add((MaplePlayerNPC) mmo);
|
||||
playerNpcs.add((PlayerNPC) mmo);
|
||||
}
|
||||
|
||||
playerNpcs.sort((p1, p2) -> {
|
||||
@@ -150,7 +150,7 @@ public class PlayerNPCPositioner {
|
||||
for (Channel ch : Server.getInstance().getChannelsFromWorld(map.getWorld())) {
|
||||
MapleMap m = ch.getMapFactory().getMap(map.getId());
|
||||
|
||||
for (MaplePlayerNPC pn : playerNpcs) {
|
||||
for (PlayerNPC pn : playerNpcs) {
|
||||
m.removeMapObject(pn);
|
||||
m.broadcastMessage(PacketCreator.removeNPCController(pn.getObjectId()));
|
||||
m.broadcastMessage(PacketCreator.removePlayerNPC(pn.getObjectId()));
|
||||
@@ -162,7 +162,7 @@ public class PlayerNPCPositioner {
|
||||
for (Channel ch : Server.getInstance().getChannelsFromWorld(map.getWorld())) {
|
||||
MapleMap m = ch.getMapFactory().getMap(map.getId());
|
||||
|
||||
for (MaplePlayerNPC pn : playerNpcs) {
|
||||
for (PlayerNPC pn : playerNpcs) {
|
||||
m.addPlayerNPCMapObject(pn);
|
||||
m.broadcastMessage(PacketCreator.spawnPlayerNPC(pn));
|
||||
m.broadcastMessage(PacketCreator.getPlayerNPC(pn));
|
||||
|
||||
@@ -352,7 +352,7 @@ public class MapleMap {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void addPlayerNPCMapObject(MaplePlayerNPC pnpcobject) {
|
||||
public void addPlayerNPCMapObject(PlayerNPC pnpcobject) {
|
||||
objectWLock.lock();
|
||||
try {
|
||||
this.mapobjects.put(pnpcobject.getObjectId(), pnpcobject);
|
||||
|
||||
@@ -242,16 +242,16 @@ public class MapleMapFactory {
|
||||
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
map.addPlayerNPCMapObject(new MaplePlayerNPC(rs));
|
||||
map.addPlayerNPCMapObject(new PlayerNPC(rs));
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
List<MaplePlayerNPC> dnpcs = MaplePlayerNPCFactory.getDeveloperNpcsFromMapid(mapid);
|
||||
List<PlayerNPC> dnpcs = MaplePlayerNPCFactory.getDeveloperNpcsFromMapid(mapid);
|
||||
if (dnpcs != null) {
|
||||
for (MaplePlayerNPC dnpc : dnpcs) {
|
||||
for (PlayerNPC dnpc : dnpcs) {
|
||||
map.addPlayerNPCMapObject(dnpc);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user