Fix unable to create playernpc
The initialization of the running world counters depended on worlds already having been initialized, so I made that dependency more explicit.
This commit is contained in:
@@ -57,7 +57,7 @@ import server.SkillbookInformationProvider;
|
|||||||
import server.ThreadManager;
|
import server.ThreadManager;
|
||||||
import server.TimerManager;
|
import server.TimerManager;
|
||||||
import server.expeditions.ExpeditionBossLog;
|
import server.expeditions.ExpeditionBossLog;
|
||||||
import server.life.PlayerNPCFactory;
|
import server.life.PlayerNPC;
|
||||||
import server.quest.Quest;
|
import server.quest.Quest;
|
||||||
import service.NoteService;
|
import service.NoteService;
|
||||||
import tools.DatabaseConnection;
|
import tools.DatabaseConnection;
|
||||||
@@ -849,15 +849,15 @@ public class Server {
|
|||||||
final ExecutorService initExecutor = Executors.newFixedThreadPool(10);
|
final ExecutorService initExecutor = Executors.newFixedThreadPool(10);
|
||||||
// Run slow operations asynchronously to make startup faster
|
// Run slow operations asynchronously to make startup faster
|
||||||
final List<Future<?>> futures = new ArrayList<>();
|
final List<Future<?>> futures = new ArrayList<>();
|
||||||
futures.add(initExecutor.submit(() -> SkillFactory.loadAllSkills()));
|
futures.add(initExecutor.submit(SkillFactory::loadAllSkills));
|
||||||
futures.add(initExecutor.submit(() -> CashItemFactory.loadAllCashItems()));
|
futures.add(initExecutor.submit(CashItemFactory::loadAllCashItems));
|
||||||
futures.add(initExecutor.submit(() -> Quest.loadAllQuests()));
|
futures.add(initExecutor.submit(Quest::loadAllQuests));
|
||||||
futures.add(initExecutor.submit(() -> SkillbookInformationProvider.loadAllSkillbookInformation()));
|
futures.add(initExecutor.submit(SkillbookInformationProvider::loadAllSkillbookInformation));
|
||||||
futures.add(initExecutor.submit(() -> PlayerNPCFactory.loadFactoryMetadata()));
|
|
||||||
initExecutor.shutdown();
|
initExecutor.shutdown();
|
||||||
|
|
||||||
TimeZone.setDefault(TimeZone.getTimeZone(YamlConfig.config.server.TIMEZONE));
|
TimeZone.setDefault(TimeZone.getTimeZone(YamlConfig.config.server.TIMEZONE));
|
||||||
|
|
||||||
|
final int worldCount = Math.min(GameConstants.WORLD_NAMES.length, YamlConfig.config.server.WORLDS);
|
||||||
try (Connection con = DatabaseConnection.getConnection()) {
|
try (Connection con = DatabaseConnection.getConnection()) {
|
||||||
setAllLoggedOut(con);
|
setAllLoggedOut(con);
|
||||||
setAllMerchantsInactive(con);
|
setAllMerchantsInactive(con);
|
||||||
@@ -868,6 +868,7 @@ public class Server {
|
|||||||
CashIdGenerator.loadExistentCashIdsFromDb(con);
|
CashIdGenerator.loadExistentCashIdsFromDb(con);
|
||||||
applyAllNameChanges(con); // -- name changes can be missed by INSTANT_NAME_CHANGE --
|
applyAllNameChanges(con); // -- name changes can be missed by INSTANT_NAME_CHANGE --
|
||||||
applyAllWorldTransfers(con);
|
applyAllWorldTransfers(con);
|
||||||
|
PlayerNPC.loadRunningRankData(con, worldCount);
|
||||||
} catch (SQLException sqle) {
|
} catch (SQLException sqle) {
|
||||||
log.error("Failed to run all startup-bound database tasks", sqle);
|
log.error("Failed to run all startup-bound database tasks", sqle);
|
||||||
throw new IllegalStateException(sqle);
|
throw new IllegalStateException(sqle);
|
||||||
@@ -877,8 +878,6 @@ public class Server {
|
|||||||
initializeTimelyTasks(channelDependencies); // aggregated method for timely tasks thanks to lxconan
|
initializeTimelyTasks(channelDependencies); // aggregated method for timely tasks thanks to lxconan
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int worldCount = Math.min(GameConstants.WORLD_NAMES.length, YamlConfig.config.server.WORLDS);
|
|
||||||
|
|
||||||
for (int i = 0; i < worldCount; i++) {
|
for (int i = 0; i < worldCount; i++) {
|
||||||
initWorld();
|
initWorld();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
* @author XoticStory
|
* @author XoticStory
|
||||||
* @author Ronan
|
* @author Ronan
|
||||||
*/
|
*/
|
||||||
|
// TODO: remove dependency on custom Npc.wz. All NPCs with id 9901910 and above are custom additions for player npcs.
|
||||||
|
// In summary: NPCs 9901910-9906599 and 9977777 are custom additions to HeavenMS that should be removed.
|
||||||
public class PlayerNPC extends AbstractMapObject {
|
public class PlayerNPC extends AbstractMapObject {
|
||||||
private static final Logger log = LoggerFactory.getLogger(PlayerNPC.class);
|
private static final Logger log = LoggerFactory.getLogger(PlayerNPC.class);
|
||||||
private static final Map<Byte, List<Integer>> availablePlayerNpcScriptIds = new HashMap<>();
|
private static final Map<Byte, List<Integer>> availablePlayerNpcScriptIds = new HashMap<>();
|
||||||
@@ -67,10 +69,6 @@ public class PlayerNPC extends AbstractMapObject {
|
|||||||
private int dir, FH, RX0, RX1, CY;
|
private int dir, FH, RX0, RX1, CY;
|
||||||
private int worldRank, overallRank, worldJobRank, overallJobRank;
|
private int worldRank, overallRank, worldJobRank, overallJobRank;
|
||||||
|
|
||||||
static {
|
|
||||||
getRunningMetadata();
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
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.equips = equips;
|
||||||
this.scriptId = scriptId;
|
this.scriptId = scriptId;
|
||||||
@@ -128,6 +126,12 @@ public class PlayerNPC extends AbstractMapObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void loadRunningRankData(Connection con, int worlds) throws SQLException {
|
||||||
|
getRunningOverallRanks(con);
|
||||||
|
getRunningWorldRanks(con, worlds);
|
||||||
|
getRunningWorldJobRanks(con);
|
||||||
|
}
|
||||||
|
|
||||||
public Map<Short, Integer> getEquips() {
|
public Map<Short, Integer> getEquips() {
|
||||||
return equips;
|
return equips;
|
||||||
}
|
}
|
||||||
@@ -213,16 +217,6 @@ public class PlayerNPC extends AbstractMapObject {
|
|||||||
client.sendPacket(PacketCreator.removePlayerNPC(this.getObjectId()));
|
client.sendPacket(PacketCreator.removePlayerNPC(this.getObjectId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void getRunningMetadata() {
|
|
||||||
try (Connection con = DatabaseConnection.getConnection()) {
|
|
||||||
getRunningOverallRanks(con);
|
|
||||||
getRunningWorldRanks(con);
|
|
||||||
getRunningWorldJobRanks(con);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void getRunningOverallRanks(Connection con) throws SQLException {
|
private static void getRunningOverallRanks(Connection con) throws SQLException {
|
||||||
try (PreparedStatement ps = con.prepareStatement("SELECT max(overallrank) FROM playernpcs");
|
try (PreparedStatement ps = con.prepareStatement("SELECT max(overallrank) FROM playernpcs");
|
||||||
ResultSet rs = ps.executeQuery()) {
|
ResultSet rs = ps.executeQuery()) {
|
||||||
@@ -235,9 +229,8 @@ public class PlayerNPC extends AbstractMapObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void getRunningWorldRanks(Connection con) throws SQLException {
|
private static void getRunningWorldRanks(Connection con, int worlds) throws SQLException {
|
||||||
int numWorlds = Server.getInstance().getWorldsSize();
|
for (int i = 0; i < worlds; i++) {
|
||||||
for (int i = 0; i < numWorlds; i++) {
|
|
||||||
runningWorldRank.add(new AtomicInteger(1));
|
runningWorldRank.add(new AtomicInteger(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,7 +239,7 @@ public class PlayerNPC extends AbstractMapObject {
|
|||||||
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
int wid = rs.getInt(1);
|
int wid = rs.getInt(1);
|
||||||
if (wid < numWorlds) {
|
if (wid < worlds) {
|
||||||
runningWorldRank.get(wid).set(rs.getInt(2) + 1);
|
runningWorldRank.get(wid).set(rs.getInt(2) + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user