Browse Source

Garbage cleanup in SetZone().

Package reformat.
master
MagicBot 2 years ago
parent
commit
6dd7315786
  1. 2
      src/engine/db/handlers/dbCharacterPowerHandler.java
  2. 2
      src/engine/db/handlers/dbCharacterRuneHandler.java
  3. 4
      src/engine/db/handlers/dbCharacterSkillHandler.java
  4. 91
      src/engine/db/handlers/dbGuildHandler.java
  5. 9
      src/engine/db/handlers/dbHandlerBase.java
  6. 80
      src/engine/db/handlers/dbItemHandler.java
  7. 18
      src/engine/db/handlers/dbPlayerCharacterHandler.java
  8. 3
      src/engine/db/handlers/dbRuneBaseEffectHandler.java
  9. 36
      src/engine/db/handlers/dbShrineHandler.java
  10. 1
      src/engine/db/handlers/dbSkillBaseHandler.java
  11. 19
      src/engine/db/handlers/dbZoneHandler.java
  12. 26
      src/engine/gameManager/ZoneManager.java
  13. 239
      src/engine/objects/Zone.java

2
src/engine/db/handlers/dbCharacterPowerHandler.java

@ -104,7 +104,7 @@ public class dbCharacterPowerHandler extends dbHandlerBase { @@ -104,7 +104,7 @@ public class dbCharacterPowerHandler extends dbHandlerBase {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_power` WHERE CharacterID = ?")) {
preparedStatement.setLong(1, (long) objectUUID);
preparedStatement.setLong(1, objectUUID);
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {

2
src/engine/db/handlers/dbCharacterRuneHandler.java

@ -112,7 +112,7 @@ public class dbCharacterRuneHandler extends dbHandlerBase { @@ -112,7 +112,7 @@ public class dbCharacterRuneHandler extends dbHandlerBase {
preparedStatement.setInt(1, characterRune.getPlayerID());
preparedStatement.setInt(2, characterRune.getRuneBaseID());
preparedStatement.setLong(3, (long) characterRune.getObjectUUID());
preparedStatement.setLong(3, characterRune.getObjectUUID());
preparedStatement.execute();

4
src/engine/db/handlers/dbCharacterSkillHandler.java

@ -134,7 +134,7 @@ public class dbCharacterSkillHandler extends dbHandlerBase { @@ -134,7 +134,7 @@ public class dbCharacterSkillHandler extends dbHandlerBase {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_skill` SET `trains`=? WHERE `UID` = ?")) {
preparedStatement.setShort(1, (short) characterSkill.getNumTrains());
preparedStatement.setLong(2, (long) characterSkill.getObjectUUID());
preparedStatement.setLong(2, characterSkill.getObjectUUID());
if (preparedStatement.executeUpdate() != 0)
characterSkill.syncTrains();
@ -162,7 +162,7 @@ public class dbCharacterSkillHandler extends dbHandlerBase { @@ -162,7 +162,7 @@ public class dbCharacterSkillHandler extends dbHandlerBase {
preparedStatement.setInt(1, characterSkill.getSkillsBase().getObjectUUID());
preparedStatement.setInt(2, CharacterSkill.GetOwner(characterSkill).getObjectUUID());
preparedStatement.setShort(3, (short) characterSkill.getNumTrains());
preparedStatement.setLong(4, (long) characterSkill.getObjectUUID());
preparedStatement.setLong(4, characterSkill.getObjectUUID());
if (preparedStatement.executeUpdate() != 0)
characterSkill.syncTrains();

91
src/engine/db/handlers/dbGuildHandler.java

@ -27,6 +27,44 @@ public class dbGuildHandler extends dbHandlerBase { @@ -27,6 +27,44 @@ public class dbGuildHandler extends dbHandlerBase {
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
}
public static ArrayList<PlayerCharacter> GET_GUILD_BANISHED(final int id) {
return new ArrayList<>();
// Bugfix
// prepareCallable("SELECT * FROM `obj_character`, `dyn_guild_banishlist` WHERE `obj_character.char_isActive` = 1 AND `dyn_guild_banishlist.CharacterID` = `obj_character.UID` AND `obj_character.GuildID`=?");
//prepareCallable("SELECT * FROM `obj_character` `,` `dyn_guild_banishlist` WHERE obj_character.char_isActive = 1 AND dyn_guild_banishlist.CharacterID = obj_character.UID AND dyn_guild_banishlist.GuildID = ?");
//setLong(1, (long) id);
//return getObjectList();
}
public static void LOAD_GUILD_HISTORY_FOR_PLAYER(PlayerCharacter playerCharacter) {
if (playerCharacter == null)
return;
ArrayList<GuildHistory> guildList = new ArrayList<>();
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_guild_allianceenemylist` WHERE `GuildID` = ?")) {
preparedStatement.setInt(1, playerCharacter.getObjectUUID());
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
GuildHistory guildEntry = new GuildHistory(rs);
guildList.add(guildEntry);
}
} catch (SQLException e) {
Logger.error(e);
}
playerCharacter.setGuildHistory(guildList);
}
public int BANISH_FROM_GUILD_OFFLINE(final int target, boolean sourceIsGuildLeader) {
String queryString;
@ -55,13 +93,12 @@ public class dbGuildHandler extends dbHandlerBase { @@ -55,13 +93,12 @@ public class dbGuildHandler extends dbHandlerBase {
return rowCount;
}
public boolean ADD_TO_BANISHED_FROM_GUILDLIST(int target, long characterID) {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_guild_banishlist` (`GuildID`, `CharacterID`) VALUES (?,?)")) {
preparedStatement.setLong(1, (long) target);
preparedStatement.setLong(1, target);
preparedStatement.setLong(2, characterID);
return (preparedStatement.executeUpdate() > 0);
@ -77,7 +114,7 @@ public class dbGuildHandler extends dbHandlerBase { @@ -77,7 +114,7 @@ public class dbGuildHandler extends dbHandlerBase {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_guild_banishlist` (`GuildID`, `CharacterID`) VALUES (?,?)")) {
preparedStatement.setLong(1, (long) target);
preparedStatement.setLong(1, target);
preparedStatement.setLong(2, characterID);
return (preparedStatement.executeUpdate() > 0);
@ -152,19 +189,6 @@ public class dbGuildHandler extends dbHandlerBase { @@ -152,19 +189,6 @@ public class dbGuildHandler extends dbHandlerBase {
}
public static ArrayList<PlayerCharacter> GET_GUILD_BANISHED(final int id) {
return new ArrayList<>();
// Bugfix
// prepareCallable("SELECT * FROM `obj_character`, `dyn_guild_banishlist` WHERE `obj_character.char_isActive` = 1 AND `dyn_guild_banishlist.CharacterID` = `obj_character.UID` AND `obj_character.GuildID`=?");
//prepareCallable("SELECT * FROM `obj_character` `,` `dyn_guild_banishlist` WHERE obj_character.char_isActive = 1 AND dyn_guild_banishlist.CharacterID = obj_character.UID AND dyn_guild_banishlist.GuildID = ?");
//setLong(1, (long) id);
//return getObjectList();
}
public ArrayList<Guild> GET_GUILD_ENEMIES(final int id) {
ArrayList<Guild> guildList = null;
@ -485,6 +509,10 @@ public class dbGuildHandler extends dbHandlerBase { @@ -485,6 +509,10 @@ public class dbGuildHandler extends dbHandlerBase {
return false;
}
// *** Refactor: Why are we saving tags/charter in update?
// It's not like this shit ever changes.
public int UPDATE_GUILD_STATUS_OFFLINE(int target, boolean isInnerCouncil, boolean isRecruiter, boolean isTaxCollector, int guildId) {
int updateMask = 0;
@ -532,10 +560,6 @@ public class dbGuildHandler extends dbHandlerBase { @@ -532,10 +560,6 @@ public class dbGuildHandler extends dbHandlerBase {
return row_count;
}
// *** Refactor: Why are we saving tags/charter in update?
// It's not like this shit ever changes.
public boolean updateDatabase(final Guild g) {
try (Connection connection = DbManager.getConnection();
@ -552,7 +576,7 @@ public class dbGuildHandler extends dbHandlerBase { @@ -552,7 +576,7 @@ public class dbGuildHandler extends dbHandlerBase {
preparedStatement.setString(9, g.getICMOTD());
preparedStatement.setString(10, "");
preparedStatement.setInt(11, g.getGuildLeaderUUID());
preparedStatement.setLong(12, (long) g.getObjectUUID());
preparedStatement.setLong(12, g.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
@ -669,31 +693,6 @@ public class dbGuildHandler extends dbHandlerBase { @@ -669,31 +693,6 @@ public class dbGuildHandler extends dbHandlerBase {
}
}
public static void LOAD_GUILD_HISTORY_FOR_PLAYER(PlayerCharacter playerCharacter) {
if (playerCharacter == null)
return;
ArrayList<GuildHistory> guildList = new ArrayList<>();
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_guild_allianceenemylist` WHERE `GuildID` = ?")) {
preparedStatement.setInt(1, playerCharacter.getObjectUUID());
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
GuildHistory guildEntry = new GuildHistory(rs);
guildList.add(guildEntry);
}
} catch (SQLException e) {
Logger.error(e);
}
playerCharacter.setGuildHistory(guildList);
}
//TODO uncomment this when finished with guild history warehouse integration
// public HashMap<Integer, GuildRecord> GET_WAREHOUSE_GUILD_HISTORY(){
//

9
src/engine/db/handlers/dbHandlerBase.java

@ -25,13 +25,13 @@ import java.util.HashSet; @@ -25,13 +25,13 @@ import java.util.HashSet;
public abstract class dbHandlerBase {
protected final ThreadLocal<CallableStatement> callableStatement = new ThreadLocal<>();
protected final ThreadLocal<Connection> connection = new ThreadLocal<>();
/*
* CallableStatements handled below this line!
*/
protected Class<? extends AbstractGameObject> localClass = null;
protected GameObjectType localObjectType;
protected final ThreadLocal<CallableStatement> callableStatement = new ThreadLocal<>();
protected final ThreadLocal<Connection> connection = new ThreadLocal<>();
protected final void prepareCallable(final String sql) {
try {
@ -392,7 +392,8 @@ public abstract class dbHandlerBase { @@ -392,7 +392,8 @@ public abstract class dbHandlerBase {
this.connection.get().close();
} catch (SQLException e) {}
} catch (SQLException e) {
}
}
protected <T extends AbstractGameObject> ArrayList<T> getObjectList() {
@ -458,7 +459,7 @@ public abstract class dbHandlerBase { @@ -458,7 +459,7 @@ public abstract class dbHandlerBase {
protected HashSet<Integer> getIntegerList(final int columnNumber) {
if (MBServerStatics.DB_ENABLE_QUERY_OUTPUT)
Logger.info("[GetIntegerList] Executing query:" + this.callableStatement.toString());
Logger.info("[GetIntegerList] Executing query:" + this.callableStatement);
HashSet<Integer> out = new HashSet<>();

80
src/engine/db/handlers/dbItemHandler.java

@ -32,6 +32,26 @@ public class dbItemHandler extends dbHandlerBase { @@ -32,6 +32,26 @@ public class dbItemHandler extends dbHandlerBase {
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
}
private static String formatTradeString(HashSet<Integer> list) {
int size = list.size();
String ret = "";
if (size == 0)
return ret;
boolean start = true;
for (int i : list) {
if (start) {
ret += i;
start = false;
} else
ret += "," + i;
}
return ret;
}
public Item ADD_ITEM(Item toAdd) {
try (Connection connection = DbManager.getConnection();
@ -122,13 +142,13 @@ public class dbItemHandler extends dbHandlerBase { @@ -122,13 +142,13 @@ public class dbItemHandler extends dbHandlerBase {
PreparedStatement preparedStatement = connection.prepareStatement("CALL `item_TRADE`(?, ?, ?, ?, ?, ?, ?, ?)")) {
preparedStatement.setString(1, formatTradeString(from1));
preparedStatement.setLong(2, (long) ac1.getObjectUUID());
preparedStatement.setLong(2, ac1.getObjectUUID());
preparedStatement.setString(3, formatTradeString(from2));
preparedStatement.setLong(4, (long) ac2.getObjectUUID());
preparedStatement.setLong(4, ac2.getObjectUUID());
preparedStatement.setInt(5, goldFrom1);
preparedStatement.setLong(6, (long) inventoryGold1.getObjectUUID());
preparedStatement.setLong(6, inventoryGold1.getObjectUUID());
preparedStatement.setInt(7, goldFrom2);
preparedStatement.setLong(8, (long) inventoryGold2.getObjectUUID());
preparedStatement.setLong(8, inventoryGold2.getObjectUUID());
ResultSet rs = preparedStatement.executeQuery();
@ -141,26 +161,6 @@ public class dbItemHandler extends dbHandlerBase { @@ -141,26 +161,6 @@ public class dbItemHandler extends dbHandlerBase {
return worked;
}
private static String formatTradeString(HashSet<Integer> list) {
int size = list.size();
String ret = "";
if (size == 0)
return ret;
boolean start = true;
for (int i : list) {
if (start) {
ret += i;
start = false;
} else
ret += "," + i;
}
return ret;
}
public ArrayList<Item> GET_EQUIPPED_ITEMS(final int targetId) {
ArrayList<Item> itemList;
@ -168,7 +168,7 @@ public class dbItemHandler extends dbHandlerBase { @@ -168,7 +168,7 @@ public class dbItemHandler extends dbHandlerBase {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`parent`=? && `obj_item`.`item_container`='equip';")) {
preparedStatement.setLong(1, (long) targetId);
preparedStatement.setLong(1, targetId);
ResultSet rs = preparedStatement.executeQuery();
itemList = getObjectsFromRs(rs, 10);
@ -207,7 +207,7 @@ public class dbItemHandler extends dbHandlerBase { @@ -207,7 +207,7 @@ public class dbItemHandler extends dbHandlerBase {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`parent`=?;")) {
preparedStatement.setLong(1, (long) accountId);
preparedStatement.setLong(1, accountId);
ResultSet rs = preparedStatement.executeQuery();
itemList = getObjectsFromRs(rs, 100);
@ -245,7 +245,7 @@ public class dbItemHandler extends dbHandlerBase { @@ -245,7 +245,7 @@ public class dbItemHandler extends dbHandlerBase {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`parent`=?")) {
preparedStatement.setLong(1, (long) id);
preparedStatement.setLong(1, id);
ResultSet rs = preparedStatement.executeQuery();
itemList = getObjectsFromRs(rs, 100);
@ -265,12 +265,12 @@ public class dbItemHandler extends dbHandlerBase { @@ -265,12 +265,12 @@ public class dbItemHandler extends dbHandlerBase {
int newFromAmt = from.getNumOfItems() - amt;
int newToAmt = to.getNumOfItems() + amt;
preparedStatement.setLong(1, (long) from.getObjectUUID());
preparedStatement.setLong(1, from.getObjectUUID());
preparedStatement.setInt(2, newFromAmt);
preparedStatement.setLong(3, (long) to.getObjectUUID());
preparedStatement.setLong(3, to.getObjectUUID());
preparedStatement.setInt(4, newToAmt);
preparedStatement.setLong(5, (long) from.getObjectUUID());
preparedStatement.setLong(6, (long) to.getObjectUUID());
preparedStatement.setLong(5, from.getObjectUUID());
preparedStatement.setLong(6, to.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
@ -292,7 +292,7 @@ public class dbItemHandler extends dbHandlerBase { @@ -292,7 +292,7 @@ public class dbItemHandler extends dbHandlerBase {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` LEFT JOIN `object` ON `object`.`UID` = `obj_item`.`UID` SET `object`.`parent`=NULL, `obj_item`.`item_container`='none' WHERE `object`.`UID`=?;")) {
preparedStatement.setLong(1, (long) item.getObjectUUID());
preparedStatement.setLong(1, item.getObjectUUID());
worked = (preparedStatement.executeUpdate() > 0);
if (worked)
@ -383,8 +383,8 @@ public class dbItemHandler extends dbHandlerBase { @@ -383,8 +383,8 @@ public class dbItemHandler extends dbHandlerBase {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_durabilityCurrent`=? WHERE `UID`=? AND `item_durabilityCurrent`=?")) {
preparedStatement.setInt(1, value);
preparedStatement.setLong(2, (long) item.getObjectUUID());
preparedStatement.setInt(3, (int) item.getDurabilityCurrent());
preparedStatement.setLong(2, item.getObjectUUID());
preparedStatement.setInt(3, item.getDurabilityCurrent());
return (preparedStatement.executeUpdate() > 0);
@ -400,7 +400,7 @@ public class dbItemHandler extends dbHandlerBase { @@ -400,7 +400,7 @@ public class dbItemHandler extends dbHandlerBase {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_container` = ? WHERE `UID` = ? AND `item_container` = 'forge';")) {
preparedStatement.setString(1, "inventory");
preparedStatement.setLong(2, (long) item.getObjectUUID());
preparedStatement.setLong(2, item.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
@ -437,7 +437,7 @@ public class dbItemHandler extends dbHandlerBase { @@ -437,7 +437,7 @@ public class dbItemHandler extends dbHandlerBase {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems`=? WHERE `UID`=?")) {
preparedStatement.setInt(1, newValue);
preparedStatement.setLong(2, (long) item.getObjectUUID());
preparedStatement.setLong(2, item.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
@ -454,7 +454,7 @@ public class dbItemHandler extends dbHandlerBase { @@ -454,7 +454,7 @@ public class dbItemHandler extends dbHandlerBase {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_chargesRemaining` = ? WHERE `UID` = ?")) {
preparedStatement.setInt(1, item.getChargesRemaining());
preparedStatement.setLong(2, (long) item.getObjectUUID());
preparedStatement.setLong(2, item.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
@ -473,7 +473,7 @@ public class dbItemHandler extends dbHandlerBase { @@ -473,7 +473,7 @@ public class dbItemHandler extends dbHandlerBase {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems`=0 WHERE `UID` = ?")) {
preparedStatement.setLong(1, (long) item.getObjectUUID());
preparedStatement.setLong(1, item.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
@ -489,7 +489,7 @@ public class dbItemHandler extends dbHandlerBase { @@ -489,7 +489,7 @@ public class dbItemHandler extends dbHandlerBase {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_flags`=? WHERE `UID` = ?")) {
preparedStatement.setInt(1, item.getFlags());
preparedStatement.setLong(2, (long) item.getObjectUUID());
preparedStatement.setLong(2, item.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
@ -505,7 +505,7 @@ public class dbItemHandler extends dbHandlerBase { @@ -505,7 +505,7 @@ public class dbItemHandler extends dbHandlerBase {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_value`=? WHERE `UID` = ?")) {
preparedStatement.setInt(1, value);
preparedStatement.setLong(2, (long) item.getObjectUUID());
preparedStatement.setLong(2, item.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);

18
src/engine/db/handlers/dbPlayerCharacterHandler.java

@ -106,7 +106,7 @@ public class dbPlayerCharacterHandler extends dbHandlerBase { @@ -106,7 +106,7 @@ public class dbPlayerCharacterHandler extends dbHandlerBase {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_character`.*, `object`.`parent` FROM `object` INNER JOIN `obj_character` ON `obj_character`.`UID` = `object`.`UID` WHERE `object`.`parent`=? && `obj_character`.`char_isActive`='1';")) {
preparedStatement.setLong(1, (long) id);
preparedStatement.setLong(1, id);
ResultSet rs = preparedStatement.executeQuery();
characterList = getObjectsFromRs(rs, 10);
@ -135,12 +135,10 @@ public class dbPlayerCharacterHandler extends dbHandlerBase { @@ -135,12 +135,10 @@ public class dbPlayerCharacterHandler extends dbHandlerBase {
}
/**
*
* <code>getFirstName</code> looks up the first name of a PlayerCharacter by
* first checking the GOM cache and then querying the database.
* PlayerCharacter objects that are not already cached won't be instantiated
* and cached.
*
*/
public ConcurrentHashMap<Integer, String> GET_IGNORE_LIST(final int objectUUID, final boolean skipActiveCheck) {
@ -192,7 +190,6 @@ public class dbPlayerCharacterHandler extends dbHandlerBase { @@ -192,7 +190,6 @@ public class dbPlayerCharacterHandler extends dbHandlerBase {
} catch (SQLException e) {
Logger.error(e);
}
;
return playerCharacter;
}
@ -256,7 +253,7 @@ public class dbPlayerCharacterHandler extends dbHandlerBase { @@ -256,7 +253,7 @@ public class dbPlayerCharacterHandler extends dbHandlerBase {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_isActive`=? WHERE `UID` = ?")) {
preparedStatement.setBoolean(1, status);
preparedStatement.setLong(2, (long) pc.getObjectUUID());
preparedStatement.setLong(2, pc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
@ -272,7 +269,7 @@ public class dbPlayerCharacterHandler extends dbHandlerBase { @@ -272,7 +269,7 @@ public class dbPlayerCharacterHandler extends dbHandlerBase {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_bindBuilding`=? WHERE `UID` = ?")) {
preparedStatement.setInt(1, bindBuildingID);
preparedStatement.setLong(2, (long) pc.getObjectUUID());
preparedStatement.setLong(2, pc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
@ -288,7 +285,7 @@ public class dbPlayerCharacterHandler extends dbHandlerBase { @@ -288,7 +285,7 @@ public class dbPlayerCharacterHandler extends dbHandlerBase {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `anniversery`=? WHERE `UID` = ?")) {
preparedStatement.setBoolean(1, flag);
preparedStatement.setLong(2, (long) pc.getObjectUUID());
preparedStatement.setLong(2, pc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
@ -305,7 +302,7 @@ public class dbPlayerCharacterHandler extends dbHandlerBase { @@ -305,7 +302,7 @@ public class dbPlayerCharacterHandler extends dbHandlerBase {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_experience`=? WHERE `UID` = ?")) {
preparedStatement.setInt(1, pc.getExp());
preparedStatement.setLong(2, (long) pc.getObjectUUID());
preparedStatement.setLong(2, pc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
@ -321,7 +318,7 @@ public class dbPlayerCharacterHandler extends dbHandlerBase { @@ -321,7 +318,7 @@ public class dbPlayerCharacterHandler extends dbHandlerBase {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guildUID`=? WHERE `UID` = ?")) {
preparedStatement.setInt(1, guildUUID);
preparedStatement.setLong(2, (long) pc.getObjectUUID());
preparedStatement.setLong(2, pc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
@ -341,7 +338,7 @@ public class dbPlayerCharacterHandler extends dbHandlerBase { @@ -341,7 +338,7 @@ public class dbPlayerCharacterHandler extends dbHandlerBase {
preparedStatement.setInt(3, pc.getConMod());
preparedStatement.setInt(4, pc.getIntMod());
preparedStatement.setInt(5, pc.getSpiMod());
preparedStatement.setLong(6, (long) pc.getObjectUUID());
preparedStatement.setLong(6, pc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
@ -360,7 +357,6 @@ public class dbPlayerCharacterHandler extends dbHandlerBase { @@ -360,7 +357,6 @@ public class dbPlayerCharacterHandler extends dbHandlerBase {
preparedStatement.setLong(1, playerCharacter.getObjectUUID());
preparedStatement.setString(2, name);
;
preparedStatement.setString(3, String.valueOf(new_value));
ResultSet rs = preparedStatement.executeQuery();

3
src/engine/db/handlers/dbRuneBaseEffectHandler.java

@ -79,8 +79,7 @@ public class dbRuneBaseEffectHandler extends dbHandlerBase { @@ -79,8 +79,7 @@ public class dbRuneBaseEffectHandler extends dbHandlerBase {
ArrayList<RuneBaseEffect> runeBaseEffectList = new ArrayList<>();
runeBaseEffectList.add((RuneBaseEffect) runeBaseEffect);
runeBaseEffectSet.put(runeBaseID, runeBaseEffectList);
}
else{
} else {
ArrayList<RuneBaseEffect> runeBaseEffectList = runeBaseEffectSet.get(runeBaseID);
runeBaseEffectList.add((RuneBaseEffect) runeBaseEffect);
runeBaseEffectSet.put(runeBaseID, runeBaseEffectList);

36
src/engine/db/handlers/dbShrineHandler.java

@ -31,6 +31,24 @@ public class dbShrineHandler extends dbHandlerBase { @@ -31,6 +31,24 @@ public class dbShrineHandler extends dbHandlerBase {
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
}
public static void addObject(ArrayList<AbstractGameObject> list, ResultSet rs) throws SQLException {
String type = rs.getString("type");
switch (type) {
case "building":
Building building = new Building(rs);
DbManager.addToCache(building);
list.add(building);
break;
case "shrine":
Shrine shrine = new Shrine(rs);
DbManager.addToCache(shrine);
list.add(shrine);
break;
}
}
public ArrayList<AbstractGameObject> CREATE_SHRINE(int parentZoneID, int OwnerUUID, String name, int meshUUID,
Vector3fImmutable location, float meshScale, int currentHP,
ProtectionState protectionState, int currentGold, int rank,
@ -103,24 +121,6 @@ public class dbShrineHandler extends dbHandlerBase { @@ -103,24 +121,6 @@ public class dbShrineHandler extends dbHandlerBase {
}
public static void addObject(ArrayList<AbstractGameObject> list, ResultSet rs) throws SQLException {
String type = rs.getString("type");
switch (type) {
case "building":
Building building = new Building(rs);
DbManager.addToCache(building);
list.add(building);
break;
case "shrine":
Shrine shrine = new Shrine(rs);
DbManager.addToCache(shrine);
list.add(shrine);
break;
}
}
public void LOAD_ALL_SHRINES() {
Shrine shrine;

1
src/engine/db/handlers/dbSkillBaseHandler.java

@ -101,7 +101,6 @@ public class dbSkillBaseHandler extends dbHandlerBase { @@ -101,7 +101,6 @@ public class dbSkillBaseHandler extends dbHandlerBase {
}
} catch (SQLException e) {
Logger.error(e.getErrorCode() + ' ' + e.getMessage(), e);
} finally {

19
src/engine/db/handlers/dbZoneHandler.java

@ -11,6 +11,8 @@ package engine.db.handlers; @@ -11,6 +11,8 @@ package engine.db.handlers;
import engine.Enum;
import engine.gameManager.DbManager;
import engine.gameManager.ZoneManager;
import engine.math.Vector2f;
import engine.objects.Zone;
import org.pmw.tinylog.Logger;
@ -77,7 +79,7 @@ public class dbZoneHandler extends dbHandlerBase { @@ -77,7 +79,7 @@ public class dbZoneHandler extends dbHandlerBase {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_zone`.*, `object`.`parent` FROM `object` INNER JOIN `obj_zone` ON `obj_zone`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;")) {
preparedStatement.setLong(1, (long) objectUUID);
preparedStatement.setLong(1, objectUUID);
ResultSet rs = preparedStatement.executeQuery();
zoneList = getObjectsFromRs(rs, 2000);
@ -89,19 +91,24 @@ public class dbZoneHandler extends dbHandlerBase { @@ -89,19 +91,24 @@ public class dbZoneHandler extends dbHandlerBase {
return zoneList;
}
public ResultSet GET_ZONE_EXTENTS(final int loadNum) {
public void LOAD_ZONE_EXTENTS() {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_zone_size` WHERE `loadNum`=?;")) {
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_zone_size`;")) {
preparedStatement.setInt(1, loadNum);
ResultSet rs = preparedStatement.executeQuery();
return preparedStatement.executeQuery();
while (rs.next()) {
Vector2f zoneSize = new Vector2f();
int loadNum = rs.getInt("loadNum");
zoneSize.x = rs.getFloat("xRadius");
zoneSize.y = rs.getFloat("zRadius");
ZoneManager._zone_size_data.put(loadNum, zoneSize);
}
} catch (SQLException e) {
Logger.error(e);
}
return null;
}
public boolean DELETE_ZONE(final Zone zone) {

26
src/engine/gameManager/ZoneManager.java

@ -24,10 +24,7 @@ import org.pmw.tinylog.Logger; @@ -24,10 +24,7 @@ import org.pmw.tinylog.Logger;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;
@ -39,17 +36,18 @@ public enum ZoneManager { @@ -39,17 +36,18 @@ public enum ZoneManager {
ZONEMANAGER;
public static Instant hotZoneLastUpdate;
/* Instance variables */
private static Zone seaFloor = null;
public static Zone hotZone = null;
public static int hotZoneCycle = 0; // Used with HOTZONE_DURATION from config.
public static final Set<Zone> macroZones = Collections.newSetFromMap(new ConcurrentHashMap<>());
private static final ConcurrentHashMap<Integer, Zone> zonesByID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD);
private static final ConcurrentHashMap<Integer, Zone> zonesByUUID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD);
private static final ConcurrentHashMap<String, Zone> zonesByName = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD);
public static final Set<Zone> macroZones = Collections.newSetFromMap(new ConcurrentHashMap<>());
private static final Set<Zone> npcCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>());
private static final Set<Zone> playerCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>());
public static Instant hotZoneLastUpdate;
public static Zone hotZone = null;
public static int hotZoneCycle = 0; // Used with HOTZONE_DURATION from config.
public static HashMap<Integer, Vector2f> _zone_size_data = new HashMap<>();
/* Instance variables */
private static Zone seaFloor = null;
// Find all zones coordinates fit into, starting with Sea Floor
@ -170,14 +168,14 @@ public enum ZoneManager { @@ -170,14 +168,14 @@ public enum ZoneManager {
return (Bounds.collide(loc, ZoneManager.hotZone.getBounds()) == true);
}
public static void setSeaFloor(final Zone value) {
ZoneManager.seaFloor = value;
}
public static Zone getSeaFloor() {
return ZoneManager.seaFloor;
}
public static void setSeaFloor(final Zone value) {
ZoneManager.seaFloor = value;
}
public static final void populateWorldZones(final Zone zone) {
int loadNum = zone.getLoadNum();

239
src/engine/objects/Zone.java

@ -30,19 +30,25 @@ import java.util.concurrent.ConcurrentHashMap; @@ -30,19 +30,25 @@ import java.util.concurrent.ConcurrentHashMap;
public class Zone extends AbstractGameObject {
public final Set<Building> zoneBuildingSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public final Set<NPC> zoneNPCSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public final Set<Mob> zoneMobSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
private final int playerCityID;
private final String zoneName;
private final float xCoord;
private final float zCoord;
private final float yCoord;
public float absX = 0.0f;
public float absY = 0.0f;
public float absZ = 0.0f;
private final int loadNum;
private final byte safeZone;
private final String Icon1;
private final String Icon2;
private final String Icon3;
public float absX = 0.0f;
public float absY = 0.0f;
public float absZ = 0.0f;
public int minLvl;
public int maxLvl;
public boolean hasBeenHotzone = false;
private ArrayList<Zone> nodes = null;
private int parentZoneID;
private Zone parent = null;
@ -50,16 +56,9 @@ public class Zone extends AbstractGameObject { @@ -50,16 +56,9 @@ public class Zone extends AbstractGameObject {
private boolean isNPCCity = false;
private boolean isPlayerCity = false;
private String hash;
public int minLvl;
public int maxLvl;
private float worldAltitude = 0;
private float seaLevel = 0;
public final Set<Building> zoneBuildingSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public final Set<NPC> zoneNPCSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public final Set<Mob> zoneMobSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public boolean hasBeenHotzone = false;
/**
* ResultSet Constructor
*/
@ -103,6 +102,59 @@ public class Zone extends AbstractGameObject { @@ -103,6 +102,59 @@ public class Zone extends AbstractGameObject {
}
public static void serializeForClientMsg(Zone zone, ByteBufferWriter writer) {
if (zone.loadNum == 0 && zone.playerCityID == 0)
Logger.warn("Warning! WorldServerMap with ID " + zone.getObjectUUID() + " has a loadnum of 0 (player city) and no city linked. This will probably crash the client!");
// Player City Terraform values serialized here.
if (zone.playerCityID > 0) {
writer.put((byte) 1); // Player City - True
writer.putFloat(Enum.CityBoundsType.ZONE.extents);
writer.putFloat(Enum.CityBoundsType.ZONE.extents);
} else
writer.put((byte) 0); // Player City - False
writer.putFloat(zone.xCoord);
writer.putFloat(zone.zCoord);
writer.putFloat(zone.yCoord);
writer.putInt(0);
writer.putInt(0);
writer.putInt(zone.loadNum);
if (zone.playerCityID > 0) {
City k = City.getCity(zone.playerCityID);
if (k != null) {
writer.putInt(k.getObjectType().ordinal());
writer.putInt(k.getObjectUUID());
} else
writer.putLong(0x0);
} else {
writer.putInt(zone.getObjectType().ordinal());
writer.putInt(zone.getObjectUUID());
}
writer.putInt(zone.nodes.size());
City city = City.getCity(zone.playerCityID);
if (city != null)
writer.putString(city.getCityName());
else
writer.putString(zone.zoneName);
writer.put(zone.safeZone);
writer.putString(zone.Icon1);
writer.putString(zone.Icon2);
writer.putString(zone.Icon3);
writer.put((byte) 0); // Pad
for (Zone child : zone.nodes) {
Zone.serializeForClientMsg(child, writer);
}
}
/* Method sets a default value for player cities
* otherwise using values derived from the loadnum
* field in the obj_zone database table.
@ -123,38 +175,18 @@ public class Zone extends AbstractGameObject { @@ -123,38 +175,18 @@ public class Zone extends AbstractGameObject {
return;
}
// All other zones have bounding boxes loaded from database
ResultSet rs = DbManager.ZoneQueries.GET_ZONE_EXTENTS(this.loadNum);
boolean loaded = false;
Vector2f zoneSize = ZoneManager._zone_size_data.get(this.loadNum);
if (rs != null)
try {
if (rs.next()) {
halfExtentX = rs.getFloat("xRadius");
halfExtentY = rs.getFloat("zRadius");
this.bounds.setBounds(new Vector2f(this.absX, this.absZ), new Vector2f(halfExtentX, halfExtentY), 0.0f);
loaded = true;
}
} catch (SQLException e) {
Logger.error("SQLException: " + e.getMessage());
}
if (!loaded) {
// Default to Citygrid size on error
// Default to player zone size on error? Maybe log this
if (zoneSize != null)
this.bounds.setBounds(new Vector2f(this.absX, this.absZ), zoneSize, 0.0f);
else
bounds.setBounds(new Vector2f(this.absX, this.absZ), new Vector2f(Enum.CityBoundsType.ZONE.extents, Enum.CityBoundsType.ZONE.extents), 0.0f);
}
}
/*
* Getters
*/
public int getPlayerCityUUID() {
if (this.playerCityID == 0)
return 0;
return this.playerCityID;
}
@ -178,10 +210,6 @@ public class Zone extends AbstractGameObject { @@ -178,10 +210,6 @@ public class Zone extends AbstractGameObject {
return loadNum;
}
public int getLoadNumClient() {
return loadNum;
}
public byte getSafeZone() {
return safeZone;
}
@ -190,42 +218,6 @@ public class Zone extends AbstractGameObject { @@ -190,42 +218,6 @@ public class Zone extends AbstractGameObject {
return Icon1;
}
public String getIcon2() {
return Icon2;
}
public String getIcon3() {
return Icon3;
}
public void setParent(final Zone value) {
this.parent = value;
this.parentZoneID = (this.parent != null) ? this.parent.getObjectUUID() : 0;
if (this.parent != null) {
this.absX = this.xCoord + parent.absX;
this.absY = this.yCoord + parent.absY;
this.absZ = this.zCoord + parent.absZ;
if (this.minLvl == 0 || this.maxLvl == 0){
this.minLvl = this.parent.minLvl;
this.maxLvl = this.parent.maxLvl;
}
} else { //only the Sea Floor zone does not have a parent
this.absX = this.xCoord;
this.absY = MBServerStatics.SEA_FLOOR_ALTITUDE;
this.absZ = this.zCoord;
}
// Zone AABB is set here as it's coordinate space is world requiring a parent.
this.setBounds();
if (this.getHeightMap() != null && this.getHeightMap().getSeaLevel() != 0)
this.seaLevel = this.getHeightMap().getSeaLevel();
}
public void generateWorldAltitude() {
if (ZoneManager.getSeaFloor().getObjectUUID() == this.getObjectUUID()) {
@ -273,6 +265,34 @@ public class Zone extends AbstractGameObject { @@ -273,6 +265,34 @@ public class Zone extends AbstractGameObject {
return this.parent;
}
public void setParent(final Zone value) {
this.parent = value;
this.parentZoneID = (this.parent != null) ? this.parent.getObjectUUID() : 0;
if (this.parent != null) {
this.absX = this.xCoord + parent.absX;
this.absY = this.yCoord + parent.absY;
this.absZ = this.zCoord + parent.absZ;
if (this.minLvl == 0 || this.maxLvl == 0) {
this.minLvl = this.parent.minLvl;
this.maxLvl = this.parent.maxLvl;
}
} else { //only the Sea Floor zone does not have a parent
this.absX = this.xCoord;
this.absY = MBServerStatics.SEA_FLOOR_ALTITUDE;
this.absZ = this.zCoord;
}
// Zone AABB is set here as it's coordinate space is world requiring a parent.
this.setBounds();
if (this.getHeightMap() != null && this.getHeightMap().getSeaLevel() != 0)
this.seaLevel = this.getHeightMap().getSeaLevel();
}
public float getAbsX() {
return this.absX;
}
@ -302,14 +322,14 @@ public class Zone extends AbstractGameObject { @@ -302,14 +322,14 @@ public class Zone extends AbstractGameObject {
return this.isNPCCity;
}
public boolean isPlayerCity() {
return this.isPlayerCity;
}
public void setNPCCity(boolean value) {
this.isNPCCity = value;
}
public boolean isPlayerCity() {
return this.isPlayerCity;
}
public void setPlayerCity(boolean value) {
this.isPlayerCity = value;
}
@ -336,67 +356,12 @@ public class Zone extends AbstractGameObject { @@ -336,67 +356,12 @@ public class Zone extends AbstractGameObject {
return nodes;
}
public void addNode(Zone child) {
this.nodes.add(child);
}
/*
* Serializing
*/
public static void serializeForClientMsg(Zone zone,ByteBufferWriter writer) {
if (zone.loadNum == 0 && zone.playerCityID == 0)
Logger.warn( "Warning! WorldServerMap with ID " + zone.getObjectUUID() + " has a loadnum of 0 (player city) and no city linked. This will probably crash the client!");
// Player City Terraform values serialized here.
if (zone.playerCityID > 0) {
writer.put((byte) 1); // Player City - True
writer.putFloat(Enum.CityBoundsType.ZONE.extents);
writer.putFloat(Enum.CityBoundsType.ZONE.extents);
} else
writer.put((byte) 0); // Player City - False
writer.putFloat(zone.xCoord);
writer.putFloat(zone.zCoord);
writer.putFloat(zone.yCoord);
writer.putInt(0);
writer.putInt(0);
writer.putInt(zone.loadNum);
if (zone.playerCityID > 0) {
City k = City.getCity(zone.playerCityID);
if (k != null) {
writer.putInt(k.getObjectType().ordinal());
writer.putInt(k.getObjectUUID());
}
else
writer.putLong(0x0);
} else {
writer.putInt(zone.getObjectType().ordinal());
writer.putInt(zone.getObjectUUID());
}
writer.putInt(zone.nodes.size());
City city = City.getCity(zone.playerCityID);
if (city != null)
writer.putString(city.getCityName());
else
writer.putString(zone.zoneName);
writer.put(zone.safeZone);
writer.putString(zone.Icon1);
writer.putString(zone.Icon2);
writer.putString(zone.Icon3);
writer.put((byte) 0); // Pad
for (Zone child : zone.nodes) {
Zone.serializeForClientMsg(child,writer);
}
public void addNode(Zone child) {
this.nodes.add(child);
}
@Override

Loading…
Cancel
Save