Browse Source

New collection created in handled and loaded from db

magicbox-1.5.2
MagicBot 1 year ago
parent
commit
2cc37481ca
  1. 47
      src/engine/db/handlers/dbBuildingHandler.java
  2. 14
      src/engine/gameManager/BuildingManager.java
  3. 12
      src/engine/mobileAI/MobAI.java
  4. 4
      src/engine/net/client/handlers/OpenFriendsCondemnListMsgHandler.java
  5. 34
      src/engine/net/client/msg/OpenFriendsCondemnListMsg.java
  6. 47
      src/engine/objects/Condemned.java
  7. 3
      src/engine/server/world/WorldServer.java

47
src/engine/db/handlers/dbBuildingHandler.java

@ -427,7 +427,6 @@ public class dbBuildingHandler extends dbHandlerBase { @@ -427,7 +427,6 @@ public class dbBuildingHandler extends dbHandlerBase {
public void LOAD_BUILDING_FRIENDS() {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_building_friends`")) {
@ -458,6 +457,38 @@ public class dbBuildingHandler extends dbHandlerBase { @@ -458,6 +457,38 @@ public class dbBuildingHandler extends dbHandlerBase {
}
public void LOAD_BUILDING_CONDEMNED() {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_building_condemned`")) {
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
Condemned condemned = new Condemned(rs);
// Create map if it does not yet exist
if (!BuildingManager._buildingCondemned.containsKey(condemned.buildingUUID))
BuildingManager._buildingCondemned.put(condemned.buildingUUID, new ConcurrentHashMap<>());
switch (condemned.friendType) {
case 2:
BuildingManager._buildingCondemned.get(condemned.buildingUUID).put(condemned.playerUID, condemned);
break;
case 4:
case 5:
BuildingManager._buildingCondemned.get(condemned.buildingUUID).put(condemned.guildUID, condemned);
break;
}
}
} catch (SQLException e) {
Logger.error(e);
}
}
public void LOAD_ALL_CONDEMNED_FOR_BUILDING(Building building) {
if (building == null)
@ -471,13 +502,13 @@ public class dbBuildingHandler extends dbHandlerBase { @@ -471,13 +502,13 @@ public class dbBuildingHandler extends dbHandlerBase {
while (rs.next()) {
Condemned condemned = new Condemned(rs);
switch (condemned.getFriendType()) {
switch (condemned.friendType) {
case 2:
building.getCondemned().put(condemned.getPlayerUID(), condemned);
building.getCondemned().put(condemned.playerUID, condemned);
break;
case 4:
case 5:
building.getCondemned().put(condemned.getGuildUID(), condemned);
building.getCondemned().put(condemned.guildUID, condemned);
break;
}
}
@ -725,10 +756,10 @@ public class dbBuildingHandler extends dbHandlerBase { @@ -725,10 +756,10 @@ public class dbBuildingHandler extends dbHandlerBase {
+ "WHERE`buildingUID` = ? AND `playerUID` = ? AND `guildUID` = ? AND `friendType` = ?")) {
preparedStatement.setBoolean(1, active);
preparedStatement.setInt(2, condemn.getParent());
preparedStatement.setInt(3, condemn.getPlayerUID());
preparedStatement.setInt(4, condemn.getGuildUID());
preparedStatement.setInt(5, condemn.getFriendType());
preparedStatement.setInt(2, condemn.buildingUUID);
preparedStatement.setInt(3, condemn.playerUID);
preparedStatement.setInt(4, condemn.guildUID);
preparedStatement.setInt(5, condemn.friendType);
return (preparedStatement.executeUpdate() > 0);

14
src/engine/gameManager/BuildingManager.java

@ -42,7 +42,7 @@ public enum BuildingManager { @@ -42,7 +42,7 @@ public enum BuildingManager {
public static HashMap<Integer, ArrayList<BuildingLocation>> _slotLocations = new HashMap<>();
public static HashMap<Integer, ConcurrentHashMap<Integer, BuildingFriends>> _buildingFriends = new HashMap<>();
public static HashMap<Integer, ConcurrentHashMap<Integer, Condemned>> _buildingCondemned = new HashMap<>();
public static int getAvailableSlot(Building building) {
ArrayList<BuildingLocation> slotLocations = _slotLocations.get(building.meshUUID);
@ -497,18 +497,18 @@ public enum BuildingManager { @@ -497,18 +497,18 @@ public enum BuildingManager {
Condemned condemn = building.getCondemned().get(player.getObjectUUID());
if (condemn != null && condemn.isActive())
if (condemn != null && condemn.active)
return true;
if (player.getGuild() != null) {
Condemned guildCondemn = building.getCondemned().get(player.getGuild().getObjectUUID());
if (guildCondemn != null && guildCondemn.isActive())
if (guildCondemn != null && guildCondemn.active)
return true;
Condemned nationCondemn = building.getCondemned().get(player.getGuild().getNation().getObjectUUID());
return nationCondemn != null && nationCondemn.isActive() && nationCondemn.getFriendType() == Condemned.NATION;
return nationCondemn != null && nationCondemn.active && nationCondemn.friendType == Condemned.NATION;
} else {
//TODO ADD ERRANT KOS CHECK
}
@ -516,18 +516,18 @@ public enum BuildingManager { @@ -516,18 +516,18 @@ public enum BuildingManager {
Condemned condemn = building.getCondemned().get(player.getObjectUUID());
if (condemn != null && condemn.isActive())
if (condemn != null && condemn.active)
return false;
if (player.getGuild() != null) {
Condemned guildCondemn = building.getCondemned().get(player.getGuild().getObjectUUID());
if (guildCondemn != null && guildCondemn.isActive())
if (guildCondemn != null && guildCondemn.active)
return false;
Condemned nationCondemn = building.getCondemned().get(player.getGuild().getNation().getObjectUUID());
return nationCondemn == null || !nationCondemn.isActive() || nationCondemn.getFriendType() != Condemned.NATION;
return nationCondemn == null || !nationCondemn.active || nationCondemn.friendType != Condemned.NATION;
} else {
//TODO ADD ERRANT KOS CHECK
}

12
src/engine/mobileAI/MobAI.java

@ -1175,17 +1175,17 @@ public class MobAI { @@ -1175,17 +1175,17 @@ public class MobAI {
//target is listed individually
if (entry.getValue().getPlayerUID() == target.getObjectUUID() && entry.getValue().isActive())
if (entry.getValue().playerUID == target.getObjectUUID() && entry.getValue().active)
return false;
//target's guild is listed
if (Guild.getGuild(entry.getValue().getGuildUID()) == target.getGuild())
if (Guild.getGuild(entry.getValue().guildUID) == target.getGuild())
return false;
//target's nation is listed
if (Guild.getGuild(entry.getValue().getGuildUID()) == target.getGuild().getNation())
if (Guild.getGuild(entry.getValue().guildUID) == target.getGuild().getNation())
return false;
}
return true;
@ -1197,17 +1197,17 @@ public class MobAI { @@ -1197,17 +1197,17 @@ public class MobAI {
//target is listed individually
if (entry.getValue().getPlayerUID() == target.getObjectUUID() && entry.getValue().isActive())
if (entry.getValue().playerUID == target.getObjectUUID() && entry.getValue().active)
return true;
//target's guild is listed
if (Guild.getGuild(entry.getValue().getGuildUID()) == target.getGuild())
if (Guild.getGuild(entry.getValue().guildUID) == target.getGuild())
return true;
//target's nation is listed
if (Guild.getGuild(entry.getValue().getGuildUID()) == target.getGuild().getNation())
if (Guild.getGuild(entry.getValue().guildUID) == target.getGuild().getNation())
return true;
}
}

4
src/engine/net/client/handlers/OpenFriendsCondemnListMsgHandler.java

@ -151,7 +151,7 @@ public class OpenFriendsCondemnListMsgHandler extends AbstractClientMsgHandler { @@ -151,7 +151,7 @@ public class OpenFriendsCondemnListMsgHandler extends AbstractClientMsgHandler {
if (removeCondemn == null)
return true;
if (!DbManager.BuildingQueries.REMOVE_FROM_CONDEMNED_LIST(removeCondemn.getParent(), removeCondemn.getPlayerUID(), removeCondemn.getGuildUID(), removeCondemn.getFriendType()))
if (!DbManager.BuildingQueries.REMOVE_FROM_CONDEMNED_LIST(removeCondemn.buildingUUID, removeCondemn.playerUID, removeCondemn.guildUID, removeCondemn.friendType))
return true;
sourceBuilding.getCondemned().remove(msg.getRemoveFriendID());
@ -175,7 +175,7 @@ public class OpenFriendsCondemnListMsgHandler extends AbstractClientMsgHandler { @@ -175,7 +175,7 @@ public class OpenFriendsCondemnListMsgHandler extends AbstractClientMsgHandler {
return true;
condemn.setActive(msg.isReverseKOS());
openFriendsCondemnListMsg.setReverseKOS(condemn.isActive());
openFriendsCondemnListMsg.setReverseKOS(condemn.active);
dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);
break;

34
src/engine/net/client/msg/OpenFriendsCondemnListMsg.java

@ -513,17 +513,17 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg { @@ -513,17 +513,17 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg {
writer.put((byte) 1);
switch (condemned.getFriendType()) {
switch (condemned.friendType) {
case 2:
PlayerCharacter playerCharacter = (PlayerCharacter) DbManager.getObject(engine.Enum.GameObjectType.PlayerCharacter, condemned.getPlayerUID());
PlayerCharacter playerCharacter = (PlayerCharacter) DbManager.getObject(engine.Enum.GameObjectType.PlayerCharacter, condemned.playerUID);
guild = playerCharacter.getGuild();
writer.putInt(GameObjectType.PlayerCharacter.ordinal());
writer.putInt(condemned.getPlayerUID());
writer.putInt(condemned.getFriendType());
writer.putInt(condemned.playerUID);
writer.putInt(condemned.friendType);
writer.putInt(GameObjectType.PlayerCharacter.ordinal());
writer.putInt(condemned.getPlayerUID());
writer.putInt(condemned.playerUID);
writer.putInt(0);
writer.putInt(0);
writer.putInt(GameObjectType.Guild.ordinal());
@ -531,9 +531,9 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg { @@ -531,9 +531,9 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg {
writer.putInt(guild.getObjectUUID());
else
writer.putInt(0);
writer.put(condemned.isActive() ? (byte) 1 : (byte) 0);
writer.put(condemned.active ? (byte) 1 : (byte) 0);
writer.put((byte) 0);
writer.put(condemned.isActive() ? (byte) 1 : (byte) 0);
writer.put(condemned.active ? (byte) 1 : (byte) 0);
if (playerCharacter != null)
writer.putString(playerCharacter.getFirstName());
@ -547,16 +547,16 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg { @@ -547,16 +547,16 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg {
}
break;
case 4:
guild = Guild.getGuild(condemned.getGuildUID());
guild = Guild.getGuild(condemned.guildUID);
writer.putInt(GameObjectType.Guild.ordinal());
writer.putInt(condemned.getGuildUID());
writer.putInt(condemned.getFriendType());
writer.putInt(condemned.guildUID);
writer.putInt(condemned.friendType);
writer.putLong(0);
writer.putInt(GameObjectType.Guild.ordinal());
writer.putInt(condemned.getGuildUID());
writer.putInt(condemned.guildUID);
writer.putLong(0);
writer.put((byte) 0);
writer.put(condemned.isActive() ? (byte) 1 : (byte) 0);
writer.put(condemned.active ? (byte) 1 : (byte) 0);
writer.put((byte) 0);
if (guild != null)
writer.putString(guild.getName());
@ -570,17 +570,17 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg { @@ -570,17 +570,17 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg {
GuildTag._serializeForDisplay(GuildTag.ERRANT, writer);
break;
case 5:
guild = Guild.getGuild(condemned.getGuildUID());
guild = Guild.getGuild(condemned.guildUID);
writer.putInt(GameObjectType.Guild.ordinal());
writer.putInt(condemned.getGuildUID());
writer.putInt(condemned.getFriendType());
writer.putInt(condemned.guildUID);
writer.putInt(condemned.friendType);
writer.putLong(0);
writer.putLong(0);
writer.putInt(GameObjectType.Guild.ordinal());
writer.putInt(condemned.getGuildUID());
writer.putInt(condemned.guildUID);
writer.put((byte) 0);
writer.put((byte) 0);
writer.put(condemned.isActive() ? (byte) 1 : (byte) 0);
writer.put(condemned.active ? (byte) 1 : (byte) 0);
if (guild != null)
writer.putString(guild.getName());
else

47
src/engine/objects/Condemned.java

@ -14,72 +14,45 @@ import engine.gameManager.DbManager; @@ -14,72 +14,45 @@ import engine.gameManager.DbManager;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Condemned {
public static final int INDIVIDUAL = 2;
public static final int GUILD = 4;
public static final int NATION = 5;
private int ID;
private int playerUID;
private int parent;
private int guildUID;
private int friendType;
private boolean active;
public int playerUID;
public int buildingUUID;
public int guildUID;
public int friendType;
public boolean active;
/**
* ResultSet Constructor
*/
public Condemned(ResultSet rs) throws SQLException {
this.playerUID = rs.getInt("playerUID");
this.parent = rs.getInt("buildingUID");
this.buildingUUID = rs.getInt("buildingUID");
this.guildUID = rs.getInt("guildUID");
this.friendType = rs.getInt("friendType");
this.active = rs.getBoolean("active");
}
public Condemned(int playerUID, int parent, int guildUID, int friendType) {
public Condemned(int playerUID, int buildingUUID, int guildUID, int friendType) {
super();
this.playerUID = playerUID;
this.parent = parent;
this.buildingUUID = buildingUUID;
this.guildUID = guildUID;
this.friendType = friendType;
this.active = false;
}
public int getPlayerUID() {
return playerUID;
}
public int getParent() {
return parent;
}
public int getGuildUID() {
return guildUID;
}
public int getFriendType() {
return friendType;
}
public boolean isActive() {
return active;
}
public boolean setActive(boolean active) {
if (!DbManager.BuildingQueries.updateActiveCondemn(this, active))
return false;
this.active = active;
return true;
}
}

3
src/engine/server/world/WorldServer.java

@ -321,6 +321,9 @@ public class WorldServer { @@ -321,6 +321,9 @@ public class WorldServer {
Logger.info("Initializing Building Friends");
DbManager.BuildingQueries.LOAD_BUILDING_FRIENDS();
Logger.info("Initializing Building Condemned");
DbManager.BuildingQueries.LOAD_BUILDING_CONDEMNED();
Logger.info("Initializing NPC Profits");
DbManager.NPCQueries.LOAD_NPC_PROFITS();

Loading…
Cancel
Save