diff --git a/src/engine/InterestManagement/InterestManager.java b/src/engine/InterestManagement/InterestManager.java index 854f0da9..bb0b0d76 100644 --- a/src/engine/InterestManagement/InterestManager.java +++ b/src/engine/InterestManagement/InterestManager.java @@ -12,6 +12,7 @@ import engine.Enum; import engine.Enum.DispatchChannel; import engine.Enum.GameObjectType; import engine.gameManager.GroupManager; +import engine.gameManager.PlayerManager; import engine.gameManager.SessionManager; import engine.job.JobScheduler; import engine.jobs.RefreshGroupJob; @@ -233,7 +234,7 @@ public enum InterestManager implements Runnable { if (distanceSquared > sqr(64)) player.setLastStaticLoc(player.getLoc()); - else if (player.isDirtyLoad() == false) + else if (PlayerManager.isDirtyLoad(player) == false) return; // Get Statics in range @@ -286,14 +287,14 @@ public enum InterestManager implements Runnable { lsm.addObject((Building) awo); else if (awo.getObjectType().equals(GameObjectType.Corpse)) { Corpse corpse = (Corpse) awo; - lcm = new LoadCharacterMsg(corpse, PlayerCharacter.hideNonAscii()); + lcm = new LoadCharacterMsg(corpse, PlayerManager.hideNonAscii()); Dispatch dispatch = Dispatch.borrow(player, lcm); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); } else if (awo.getObjectType().equals(GameObjectType.NPC)) { NPC npc = (NPC) awo; - lcm = new LoadCharacterMsg(npc, PlayerCharacter.hideNonAscii()); + lcm = new LoadCharacterMsg(npc, PlayerManager.hideNonAscii()); lcmList.add(lcm); } @@ -311,7 +312,7 @@ public enum InterestManager implements Runnable { } loadedStaticObjects.addAll(toLoad); - player.setDirtyLoad(false); + PlayerManager.setDirtyLoad(player, false); } private void updateMobileList(PlayerCharacter player, ClientConnection origin) { @@ -437,7 +438,7 @@ public enum InterestManager implements Runnable { if (player.getSeeInvis() < awopc.getHidden()) continue; - lcm = new LoadCharacterMsg(awopc, PlayerCharacter.hideNonAscii()); + lcm = new LoadCharacterMsg(awopc, PlayerManager.hideNonAscii()); players.add(awo); // check if in a group with the person being loaded @@ -466,11 +467,11 @@ public enum InterestManager implements Runnable { awonpc.playerAgroMap.put(player.getObjectUUID(), false); ((Mob) awonpc).setCombatTarget(null); - lcm = new LoadCharacterMsg(awonpc, PlayerCharacter.hideNonAscii()); + lcm = new LoadCharacterMsg(awonpc, PlayerManager.hideNonAscii()); } else if ((awo.getObjectTypeMask() & MBServerStatics.MASK_NPC) != 0) { NPC awonpc = (NPC) awo; - lcm = new LoadCharacterMsg(awonpc, PlayerCharacter.hideNonAscii()); + lcm = new LoadCharacterMsg(awonpc, PlayerManager.hideNonAscii()); } else if ((awo.getObjectTypeMask() & MBServerStatics.MASK_PET) != 0) { Mob awonpc = (Mob) awo; @@ -482,7 +483,7 @@ public enum InterestManager implements Runnable { if ((awonpc.agentType.equals(Enum.AIAgentType.MOBILE))) ((Mob) awonpc).setCombatTarget(null); - lcm = new LoadCharacterMsg(awonpc, PlayerCharacter.hideNonAscii()); + lcm = new LoadCharacterMsg(awonpc, PlayerManager.hideNonAscii()); } addToList.add(awo); @@ -518,8 +519,8 @@ public enum InterestManager implements Runnable { // Update loaded upbjects lists - player.isBoxed = PlayerCharacter.checkIfBoxed(player); - player.setDirtyLoad(true); + player.isBoxed = PlayerManager.checkIfBoxed(player); + PlayerManager.setDirtyLoad(player, true); updateStaticList(player, origin); updateMobileList(player, origin); } @@ -536,7 +537,7 @@ public enum InterestManager implements Runnable { // Update loaded upbjects lists - playerCharacter.setDirtyLoad(true); + PlayerManager.setDirtyLoad(playerCharacter, true); updateStaticList(playerCharacter, origin); updateMobileList(playerCharacter, origin); @@ -552,7 +553,7 @@ public enum InterestManager implements Runnable { for (AbstractWorldObject playerObject : playerList) { PlayerCharacter playerCharacter = (PlayerCharacter) playerObject; - playerCharacter.setDirtyLoad(true); + PlayerManager.setDirtyLoad(playerCharacter, true); } } } \ No newline at end of file diff --git a/src/engine/db/handlers/dbAccountHandler.java b/src/engine/db/handlers/dbAccountHandler.java index f34ebe60..484e3bd2 100644 --- a/src/engine/db/handlers/dbAccountHandler.java +++ b/src/engine/db/handlers/dbAccountHandler.java @@ -13,6 +13,7 @@ import engine.Enum; import engine.Enum.GameObjectType; import engine.gameManager.ConfigManager; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.objects.Account; import engine.objects.PlayerCharacter; import org.pmw.tinylog.Logger; @@ -140,7 +141,7 @@ public class dbAccountHandler extends dbHandlerBase { int playerID; playerID = rs.getInt(1); - trashPlayer = PlayerCharacter.getPlayerCharacter(playerID); + trashPlayer = PlayerManager.getPlayerCharacter(playerID); if (trashPlayer == null) continue; diff --git a/src/engine/db/handlers/dbCSSessionHandler.java b/src/engine/db/handlers/dbCSSessionHandler.java index 5516c733..ea7cfe8d 100644 --- a/src/engine/db/handlers/dbCSSessionHandler.java +++ b/src/engine/db/handlers/dbCSSessionHandler.java @@ -10,8 +10,8 @@ package engine.db.handlers; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.objects.Account; -import engine.objects.PlayerCharacter; import engine.session.CSSession; import engine.util.StringUtils; import org.pmw.tinylog.Logger; @@ -103,7 +103,7 @@ public class dbCSSessionHandler extends dbHandlerBase { ResultSet rs = preparedStatement.executeQuery(); if (rs.next()) - css = new CSSession(secKey, DbManager.AccountQueries.GET_ACCOUNT(rs.getInt("accountID")), PlayerCharacter.getPlayerCharacter(rs.getInt("characterID")), rs.getString("machineID")); + css = new CSSession(secKey, DbManager.AccountQueries.GET_ACCOUNT(rs.getInt("accountID")), PlayerManager.getPlayerCharacter(rs.getInt("characterID")), rs.getString("machineID")); } catch (SQLException e) { Logger.error(e); diff --git a/src/engine/db/handlers/dbGuildHandler.java b/src/engine/db/handlers/dbGuildHandler.java index a4f1998e..59dd66ed 100644 --- a/src/engine/db/handlers/dbGuildHandler.java +++ b/src/engine/db/handlers/dbGuildHandler.java @@ -12,6 +12,7 @@ package engine.db.handlers; import engine.Enum; import engine.Enum.GuildHistoryType; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.objects.*; import engine.server.world.WorldServer; import org.joda.time.DateTime; @@ -222,7 +223,7 @@ public class dbGuildHandler extends dbHandlerBase { while (rs.next()) { int playerUUID = rs.getInt(1); - PlayerCharacter kosPlayer = PlayerCharacter.getPlayerCharacter(playerUUID); + PlayerCharacter kosPlayer = PlayerManager.getPlayerCharacter(playerUUID); if (kosPlayer != null) kosList.add(kosPlayer); diff --git a/src/engine/devcmd/cmds/AuditFailedItemsCmd.java b/src/engine/devcmd/cmds/AuditFailedItemsCmd.java index e92e0b87..a2aef3d2 100644 --- a/src/engine/devcmd/cmds/AuditFailedItemsCmd.java +++ b/src/engine/devcmd/cmds/AuditFailedItemsCmd.java @@ -11,6 +11,7 @@ package engine.devcmd.cmds; import engine.Enum.ModType; import engine.devcmd.AbstractDevCmd; +import engine.gameManager.PlayerManager; import engine.gameManager.PowersManager; import engine.net.ItemProductionManager; import engine.objects.*; @@ -57,7 +58,7 @@ public class AuditFailedItemsCmd extends AbstractDevCmd { contractName = npc.getContract().getName(); } - PlayerCharacter roller = PlayerCharacter.getFromCache(failedItem.getPlayerID()); + PlayerCharacter roller = PlayerManager.getFromCache(failedItem.getPlayerID()); if (roller == null) playerName = "null"; diff --git a/src/engine/devcmd/cmds/DecachePlayerCmd.java b/src/engine/devcmd/cmds/DecachePlayerCmd.java index d4e006e2..332badbf 100644 --- a/src/engine/devcmd/cmds/DecachePlayerCmd.java +++ b/src/engine/devcmd/cmds/DecachePlayerCmd.java @@ -12,6 +12,7 @@ package engine.devcmd.cmds; import engine.Enum; import engine.devcmd.AbstractDevCmd; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.objects.AbstractGameObject; import engine.objects.PlayerCharacter; @@ -34,8 +35,8 @@ public class DecachePlayerCmd extends AbstractDevCmd { int objectUUID = Integer.parseInt(words[0]); if (DbManager.inCache(Enum.GameObjectType.PlayerCharacter, objectUUID)) { - this.setTarget(PlayerCharacter.getFromCache(objectUUID)); //for logging - PlayerCharacter.getFromCache(objectUUID).removeFromCache(); + this.setTarget(PlayerManager.getFromCache(objectUUID)); //for logging + PlayerManager.getFromCache(objectUUID).removeFromCache(); } else { this.sendHelp(pc); } diff --git a/src/engine/devcmd/cmds/GotoBoundsCmd.java b/src/engine/devcmd/cmds/GotoBoundsCmd.java index 67004d26..abe92ae3 100644 --- a/src/engine/devcmd/cmds/GotoBoundsCmd.java +++ b/src/engine/devcmd/cmds/GotoBoundsCmd.java @@ -11,6 +11,7 @@ package engine.devcmd.cmds; import engine.Enum.GameObjectType; import engine.devcmd.AbstractDevCmd; +import engine.gameManager.PlayerManager; import engine.math.Vector3fImmutable; import engine.objects.AbstractGameObject; import engine.objects.Building; @@ -89,7 +90,7 @@ public class GotoBoundsCmd extends AbstractDevCmd { return; } - player.teleport(targetLoc); + PlayerManager.teleport(player, targetLoc); } diff --git a/src/engine/devcmd/cmds/GotoCmd.java b/src/engine/devcmd/cmds/GotoCmd.java index 95ab5f93..3f59a802 100644 --- a/src/engine/devcmd/cmds/GotoCmd.java +++ b/src/engine/devcmd/cmds/GotoCmd.java @@ -12,6 +12,7 @@ package engine.devcmd.cmds; import engine.Enum.GameObjectType; import engine.devcmd.AbstractDevCmd; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.gameManager.SessionManager; import engine.math.Vector3fImmutable; import engine.objects.*; @@ -35,7 +36,7 @@ public class GotoCmd extends AbstractDevCmd { if (target != null && words[0].isEmpty()) { AbstractWorldObject targetAgo = (AbstractWorldObject) target; - pc.teleport(targetAgo.getLoc()); + PlayerManager.teleport(pc, targetAgo.getLoc()); return; } @@ -50,7 +51,7 @@ public class GotoCmd extends AbstractDevCmd { } if (loc != null) - pc.teleport(loc); + PlayerManager.teleport(pc, loc); return; } @@ -61,7 +62,7 @@ public class GotoCmd extends AbstractDevCmd { } if (loc != null) - pc.teleport(loc); + PlayerManager.teleport(pc, loc); return; } @@ -164,7 +165,7 @@ public class GotoCmd extends AbstractDevCmd { } } if (loc != null) { - pc.teleport(loc); + PlayerManager.teleport(pc, loc); } } diff --git a/src/engine/devcmd/cmds/GotoObj.java b/src/engine/devcmd/cmds/GotoObj.java index e6e69b8c..e7500e56 100644 --- a/src/engine/devcmd/cmds/GotoObj.java +++ b/src/engine/devcmd/cmds/GotoObj.java @@ -12,6 +12,7 @@ package engine.devcmd.cmds; import engine.Enum; import engine.devcmd.AbstractDevCmd; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.math.Vector3fImmutable; import engine.objects.*; @@ -84,7 +85,7 @@ public class GotoObj extends AbstractDevCmd { return; } - player.teleport(targetLoc); + PlayerManager.teleport(player, targetLoc); } diff --git a/src/engine/devcmd/cmds/InfoCmd.java b/src/engine/devcmd/cmds/InfoCmd.java index fa3445b1..f902c0ab 100644 --- a/src/engine/devcmd/cmds/InfoCmd.java +++ b/src/engine/devcmd/cmds/InfoCmd.java @@ -15,6 +15,7 @@ import engine.Enum.GameObjectType; import engine.Enum.TargetColor; import engine.devcmd.AbstractDevCmd; import engine.gameManager.BuildingManager; +import engine.gameManager.PlayerManager; import engine.gameManager.SessionManager; import engine.math.Vector3fImmutable; import engine.objects.*; @@ -335,7 +336,7 @@ public class InfoCmd extends AbstractDevCmd { output += "Altitude : " + targetPC.getLoc().y; - output += "Swimming : " + targetPC.isSwimming(); + output += "Swimming : " + PlayerManager.isSwimming(targetPC); output += newline; output += "isMoving : " + targetPC.isMoving(); output += newline; diff --git a/src/engine/devcmd/cmds/JumpCmd.java b/src/engine/devcmd/cmds/JumpCmd.java index 7da57eb3..a56a4ff6 100644 --- a/src/engine/devcmd/cmds/JumpCmd.java +++ b/src/engine/devcmd/cmds/JumpCmd.java @@ -10,6 +10,7 @@ package engine.devcmd.cmds; import engine.devcmd.AbstractDevCmd; +import engine.gameManager.PlayerManager; import engine.math.Vector3fImmutable; import engine.objects.AbstractGameObject; import engine.objects.PlayerCharacter; @@ -36,7 +37,7 @@ public class JumpCmd extends AbstractDevCmd { try { float range = Float.parseFloat(words[1]); Vector3fImmutable newLoc = pc.getFaceDir().scaleAdd(range, pc.getLoc()); - pc.teleport(newLoc); + PlayerManager.teleport(pc, newLoc); } catch (NumberFormatException e) { @@ -68,7 +69,7 @@ public class JumpCmd extends AbstractDevCmd { Vector3fImmutable loc = pc.getLoc(); loc = loc.add(lat, 0f, -lon); - pc.teleport(loc); + PlayerManager.teleport(pc, loc); } @Override diff --git a/src/engine/devcmd/cmds/MakeBaneCmd.java b/src/engine/devcmd/cmds/MakeBaneCmd.java index e4328ec0..3651256e 100644 --- a/src/engine/devcmd/cmds/MakeBaneCmd.java +++ b/src/engine/devcmd/cmds/MakeBaneCmd.java @@ -12,10 +12,7 @@ package engine.devcmd.cmds; import engine.Enum.ProtectionState; import engine.InterestManagement.WorldGrid; import engine.devcmd.AbstractDevCmd; -import engine.gameManager.BuildingManager; -import engine.gameManager.ChatManager; -import engine.gameManager.DbManager; -import engine.gameManager.ZoneManager; +import engine.gameManager.*; import engine.math.Vector3f; import engine.math.Vector3fImmutable; import engine.objects.*; @@ -74,7 +71,7 @@ public class MakeBaneCmd extends AbstractDevCmd { return; } - PlayerCharacter player = PlayerCharacter.getPlayerCharacter(attackerID); + PlayerCharacter player = PlayerManager.getPlayerCharacter(attackerID); if (player.getGuild().isEmptyGuild()) { @@ -194,7 +191,7 @@ public class MakeBaneCmd extends AbstractDevCmd { Vector3fImmutable movePlayerOutsideStone = player.getLoc(); movePlayerOutsideStone = movePlayerOutsideStone.setX(movePlayerOutsideStone.x + 10); movePlayerOutsideStone = movePlayerOutsideStone.setZ(movePlayerOutsideStone.z + 10); - player.teleport(movePlayerOutsideStone); + PlayerManager.teleport(player, movePlayerOutsideStone); throwbackInfo(pc, "The city has been succesfully baned."); } diff --git a/src/engine/devcmd/cmds/ResetLevelCmd.java b/src/engine/devcmd/cmds/ResetLevelCmd.java index aa6d1ef2..56025eb1 100644 --- a/src/engine/devcmd/cmds/ResetLevelCmd.java +++ b/src/engine/devcmd/cmds/ResetLevelCmd.java @@ -1,6 +1,7 @@ package engine.devcmd.cmds; import engine.devcmd.AbstractDevCmd; +import engine.gameManager.PlayerManager; import engine.objects.AbstractGameObject; import engine.objects.PlayerCharacter; @@ -16,7 +17,7 @@ public class ResetLevelCmd extends AbstractDevCmd { protected void _doCmd(PlayerCharacter player, String[] args, AbstractGameObject target) { - player.ResetLevel(Short.parseShort(args[0])); + PlayerManager.ResetLevel(player, Short.parseShort(args[0])); } @Override diff --git a/src/engine/devcmd/cmds/SlotTestCmd.java b/src/engine/devcmd/cmds/SlotTestCmd.java index bc31e7c2..b579ec21 100644 --- a/src/engine/devcmd/cmds/SlotTestCmd.java +++ b/src/engine/devcmd/cmds/SlotTestCmd.java @@ -13,6 +13,7 @@ import engine.Enum.GameObjectType; import engine.devcmd.AbstractDevCmd; import engine.gameManager.BuildingManager; import engine.gameManager.ChatManager; +import engine.gameManager.PlayerManager; import engine.math.Vector3fImmutable; import engine.objects.*; @@ -56,7 +57,7 @@ public class SlotTestCmd extends AbstractDevCmd { BuildingLocation buildingLocation = BuildingManager._slotLocations.get(building.meshUUID).get(slot - 1); slotLocation = building.getLoc().add(buildingLocation.getLocation()); slotLocation = Vector3fImmutable.rotateAroundPoint(building.getLoc(), slotLocation, building.getBounds().getQuaternion().angleY); - playerCharacter.teleport(slotLocation); + PlayerManager.teleport(playerCharacter, slotLocation); return; } diff --git a/src/engine/devcmd/cmds/SummonCmd.java b/src/engine/devcmd/cmds/SummonCmd.java index 184903ca..c38fb83b 100644 --- a/src/engine/devcmd/cmds/SummonCmd.java +++ b/src/engine/devcmd/cmds/SummonCmd.java @@ -10,6 +10,7 @@ package engine.devcmd.cmds; import engine.devcmd.AbstractDevCmd; +import engine.gameManager.PlayerManager; import engine.gameManager.SessionManager; import engine.gameManager.ZoneManager; import engine.math.Vector3fImmutable; @@ -91,7 +92,7 @@ public class SummonCmd extends AbstractDevCmd { this.setTarget(pcToSummon); //for logging Vector3fImmutable loc = pc.getLoc(); - pcToSummon.teleport(loc); + PlayerManager.teleport(pcToSummon, loc); this.throwbackInfo(pc, "Player " + pcToSummon.getCombinedName() + " has been summoned to your location."); diff --git a/src/engine/devcmd/cmds/aiInfoCmd.java b/src/engine/devcmd/cmds/aiInfoCmd.java index e31060bb..dc7f13a6 100644 --- a/src/engine/devcmd/cmds/aiInfoCmd.java +++ b/src/engine/devcmd/cmds/aiInfoCmd.java @@ -11,6 +11,7 @@ package engine.devcmd.cmds; import engine.Enum.GameObjectType; import engine.devcmd.AbstractDevCmd; +import engine.gameManager.PlayerManager; import engine.objects.AbstractGameObject; import engine.objects.Mob; import engine.objects.PlayerCharacter; @@ -77,7 +78,7 @@ public class aiInfoCmd extends AbstractDevCmd { output += "Players Loaded:" + newline; } for (Map.Entry entry : mob.playerAgroMap.entrySet()) { - output += "Player ID: " + entry.getKey() + " Hate Value: " + (PlayerCharacter.getPlayerCharacter(entry.getKey())).getHateValue() + newline; + output += "Player ID: " + entry.getKey() + " Hate Value: " + (PlayerManager.getPlayerCharacter(entry.getKey())).getHateValue() + newline; } if (mob.getCombatTarget() != null) output += "Current Target: " + mob.getCombatTarget().getName() + newline; diff --git a/src/engine/gameManager/CombatManager.java b/src/engine/gameManager/CombatManager.java index b1386fa1..16bdba8f 100644 --- a/src/engine/gameManager/CombatManager.java +++ b/src/engine/gameManager/CombatManager.java @@ -65,7 +65,7 @@ public enum CombatManager { targetType = msg.getTargetType(); if (targetType == GameObjectType.PlayerCharacter.ordinal()) { - target = PlayerCharacter.getFromCache(msg.getTargetID()); + target = PlayerManager.getFromCache(msg.getTargetID()); } else if (targetType == GameObjectType.Building.ordinal()) { target = BuildingManager.getBuildingFromCache(msg.getTargetID()); } else if (targetType == GameObjectType.Mob.ordinal()) { @@ -171,7 +171,7 @@ public enum CombatManager { targetType = msg.getTargetType(); if (targetType == GameObjectType.PlayerCharacter.ordinal()) - target = PlayerCharacter.getFromCache(msg.getTargetID()); + target = PlayerManager.getFromCache(msg.getTargetID()); else if (targetType == GameObjectType.Building.ordinal()) target = BuildingManager.getBuildingFromCache(msg.getTargetID()); else if (targetType == GameObjectType.Mob.ordinal()) @@ -1249,7 +1249,7 @@ public enum CombatManager { if (pc == null) return; - if(pc.isFlying()) + if(PlayerManager.isFlying(pc)) pc.setSit(false); else pc.setSit(toggle); diff --git a/src/engine/gameManager/DbManager.java b/src/engine/gameManager/DbManager.java index 92917a35..4099c331 100644 --- a/src/engine/gameManager/DbManager.java +++ b/src/engine/gameManager/DbManager.java @@ -85,7 +85,7 @@ public enum DbManager { switch (objectType) { case PlayerCharacter: - outObject = PlayerCharacter.getPlayerCharacter(objectUUID); + outObject = PlayerManager.getPlayerCharacter(objectUUID); break; case NPC: outObject = NPC.getNPC(objectUUID); diff --git a/src/engine/gameManager/GuildManager.java b/src/engine/gameManager/GuildManager.java index e6b285ae..f1f2da50 100644 --- a/src/engine/gameManager/GuildManager.java +++ b/src/engine/gameManager/GuildManager.java @@ -74,16 +74,16 @@ public enum GuildManager { } } - playerCharacter.setInnerCouncil(false); - playerCharacter.setGuildLeader(false); + PlayerManager.setInnerCouncil(playerCharacter, false); + PlayerManager.setGuildLeader(playerCharacter, false); playerCharacter.setGuild(guild); // Cleanup guild stuff - playerCharacter.resetGuildStatuses(); + PlayerManager.resetGuildStatuses(playerCharacter); // send success message to client if (fromTeleportScreen && guild.isNPCGuild()) - playerCharacter.setFullMember(true); + PlayerManager.setFullMember(playerCharacter, true); msg = new AcceptInviteToGuildMsg(guild.getObjectUUID(), 1, 0); @@ -178,7 +178,7 @@ public enum GuildManager { bindBuilding = city.getTOL(); if (bindBuilding == null) - bindBuilding = PlayerCharacter.getBindBuildingForGuild(playerCharacter); + bindBuilding = PlayerManager.getBindBuildingForGuild(playerCharacter); playerCharacter.setBindBuildingID(bindBuilding != null ? bindBuilding.getObjectUUID() : 0); } diff --git a/src/engine/gameManager/PlayerManager.java b/src/engine/gameManager/PlayerManager.java new file mode 100644 index 00000000..3dd8e020 --- /dev/null +++ b/src/engine/gameManager/PlayerManager.java @@ -0,0 +1,2392 @@ +package engine.gameManager; + +import engine.Enum; +import engine.InterestManagement.InterestManager; +import engine.InterestManagement.WorldGrid; +import engine.exception.MsgSendException; +import engine.exception.SerializationException; +import engine.job.JobContainer; +import engine.job.JobScheduler; +import engine.jobs.FinishSpireEffectJob; +import engine.jobs.NoTimeJob; +import engine.math.Vector3fImmutable; +import engine.net.ByteBufferWriter; +import engine.net.Dispatch; +import engine.net.DispatchMessage; +import engine.net.client.ClientConnection; +import engine.net.client.msg.*; +import engine.net.client.msg.login.CommitNewCharacterMsg; +import engine.objects.*; +import engine.powers.EffectsBase; +import engine.server.MBServerStatics; +import engine.server.login.LoginServer; +import engine.server.login.LoginServerMsgHandler; +import engine.server.world.WorldServer; +import engine.util.MiscUtils; +import org.joda.time.DateTime; +import org.pmw.tinylog.Logger; + +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; + +public class PlayerManager { + public static Building getUpdatedBindBuilding(PlayerCharacter player) { + Building returnBuilding = null; + + //update bindBuilding based on Guild or nation TOL; + + if (player.getBindBuildingID() == 0) { + + returnBuilding = getBindBuildingForGuild(player); + + if (returnBuilding != null) + player.setBindBuildingID(returnBuilding.getObjectUUID()); + return returnBuilding; + } + returnBuilding = BuildingManager.getBuildingFromCache(player.getBindBuildingID()); + + if (returnBuilding == null) { + returnBuilding = getBindBuildingForGuild(player); + + if (returnBuilding != null) + player.setBindBuildingID(returnBuilding.getObjectUUID()); + } + return returnBuilding; + } + + public static Building getBindBuildingForGuild(PlayerCharacter player) { + + Building returnBuilding; + + if (player.getGuild() == null || player.getGuild().isEmptyGuild()) + return null; + + if (player.getGuild().getOwnedCity() == null) { + + if (player.getGuild().getNation().getOwnedCity() == null) + return null; + + if (player.getGuild().getNation().getOwnedCity().getTOL() == null) + return null; + + returnBuilding = player.getGuild().getNation().getOwnedCity().getTOL(); + player.setBindBuildingID(returnBuilding.getObjectUUID()); + return returnBuilding; + } + + if (player.getGuild().getOwnedCity().getTOL() == null) + return null; + + returnBuilding = player.getGuild().getOwnedCity().getTOL(); + return returnBuilding; + } + + public static void __serializeForClientMsg(PlayerCharacter playerCharacter, ByteBufferWriter writer) throws SerializationException { + serializeForClientCommon(playerCharacter, writer, true, false, false, false); + } + + public static void serializeForClientMsgLogin(PlayerCharacter playerCharacter, ByteBufferWriter writer) throws SerializationException { + serializeForClientCommon(playerCharacter, writer, true, false, false, false); + } + + public static void serializeForClientMsgCommit(PlayerCharacter playerCharacter, ByteBufferWriter writer) throws SerializationException { + serializeForClientCommon(playerCharacter, writer, true, true, false, false); + } + + public static void serializeForClientMsgFull(PlayerCharacter playerCharacter, ByteBufferWriter writer) throws SerializationException { + serializeForClientCommon(playerCharacter, writer, false, false, false, false); + } + + public static void serializeForClientMsgOtherPlayer(PlayerCharacter playerCharacter, ByteBufferWriter writer) throws SerializationException { + serializeForClientCommon(playerCharacter, writer, false, false, true, false); + } + + public static void serializePlayerForClientMsgOtherPlayer(PlayerCharacter playerCharacter, ByteBufferWriter writer, boolean hideAsciiLastName) throws SerializationException { + serializeForClientCommon(playerCharacter, writer, false, false, true, hideAsciiLastName); + } + + // TODO what is a Fresh Char? + private static void serializeForClientCommon(PlayerCharacter playerCharacter, ByteBufferWriter writer, boolean loginData, boolean freshChar, boolean otherPlayer, boolean hideAsciiLastName) + throws SerializationException { + + /* + * RUNES + */ + // Handle Applied Runes + writer.putInt(0); // Pad + writer.putInt(0); // Pad + + // Put number of runes + //We need to send all runes to everyone, otherwise playerCharacter will cause major issues + if (playerCharacter.getPromotionClass() != null) + writer.putInt(playerCharacter.getRunes().size() + 3); + else + writer.putInt(playerCharacter.getRunes().size() + 2); + + // Cant forget that Race and baseClass are technically Runes :0 + if (playerCharacter.getSubRaceID() != 0) { + writer.putInt(1); // For Race + writer.putInt(0); // Pad + writer.putInt(playerCharacter.getSubRaceID()); + + writer.putInt(Enum.GameObjectType.Race.ordinal()); + writer.putInt(playerCharacter.getSubRaceID()); + } else + playerCharacter.getRace().serializeForClientMsg(writer); + if (playerCharacter.getPromotionClass() != null) { + BaseClass.serializeForClientMsg(playerCharacter.getBaseClass(), writer, 2); + PromotionClass.serializeForClientMsg(playerCharacter.getPromotionClass(), writer); + } else + BaseClass.serializeForClientMsg(playerCharacter.getBaseClass(), writer, 3); + + // Put runes. + + for (CharacterRune rb : playerCharacter.getRunes()) { + CharacterRune.serializeForClientMsg(rb, writer); + } + + /* + * STATS + */ + // Number of Stats to follow + writer.putInt(5); + + writer.putInt(MBServerStatics.STAT_STR_ID); // Strength ID + writer.putInt(freshChar ? 0 : playerCharacter.getStrMod()); + + writer.putInt(MBServerStatics.STAT_SPI_ID); // Spirit ID + writer.putInt(freshChar ? 0 : playerCharacter.getSpiMod()); + + writer.putInt(MBServerStatics.STAT_CON_ID); // Constitution ID + writer.putInt(freshChar ? 0 : playerCharacter.getConMod()); + + writer.putInt(MBServerStatics.STAT_DEX_ID); // Dexterity ID + writer.putInt(freshChar ? 0 : playerCharacter.getDexMod()); + + writer.putInt(MBServerStatics.STAT_INT_ID); // Intelligence ID + writer.putInt(freshChar ? 0 : playerCharacter.getIntMod()); + + // Handle Info + playerCharacter.title._serializeFirstName(writer, playerCharacter.getFirstName()); + playerCharacter.title._serializeLastName(writer, playerCharacter.getLastName(), hideAsciiLastName, playerCharacter.asciiLastName); + + // Unknown + writer.putInt(0); + + writer.putString(ConfigManager.MB_WORLD_NAME.getValue()); + writer.putInt(WorldServer.worldMapID); + + writer.put((byte) 1); // End Datablock byte + writer.putInt(0); // Unsure, Pad? + writer.putInt(playerCharacter.getObjectType().ordinal()); + writer.putInt(playerCharacter.getObjectUUID()); + + // Perhaps playerCharacter is loc and the next 3 are Facing dir? + writer.putFloat(1); // Unknown + writer.putFloat(playerCharacter.getRace().getRaceType().getScaleHeight()); // Unknown + writer.putFloat(1); // Unknown + + writer.putVector3f(playerCharacter.getLoc()); + writer.putFloat(playerCharacter.getFaceDir().getRotation()); // Rotation, direction + + // facing + + // Running trains. + + if (otherPlayer) { + CharacterSkill runSkill = playerCharacter.getSkills().get("Running"); + if (runSkill == null) + // Logger.log.log( + // LogEventType.WARNING, + // "Failed to find the 'Running Skill' when serializing PlayerCharacter '" + // + playerCharacter.getCombinedName() + "'"); + // TODO put int=0 for now. + writer.putInt(0); + else + writer.putInt(runSkill.getNumTrains()); + } else + writer.putInt(0); + + + ArrayList equipped = playerCharacter.getCharItemManager().getEquippedList(); + + writer.putInt(equipped.size()); + for (Item item : equipped) { + Item._serializeForClientMsg(item, writer); + } + writer.putInt(playerCharacter.getRank()); + + writer.putInt(playerCharacter.getLevel()); + if (loginData) + writer.putInt(5); + else + writer.putInt(playerCharacter.getIsSittingAsInt()); // 5 + writer.putInt(playerCharacter.getIsWalkingAsInt()); // 1 + writer.putInt(playerCharacter.getIsCombatAsInt()); // 1 + writer.putInt(playerCharacter.getIsFlightAsInt()); // 2 or 3 + + writer.putInt(playerCharacter.getIsLfGroupAsInt()); // 1 + + // if (loginData) + // writer.putInt(0); + // else + writer.putInt(playerCharacter.getHeadlightsAsInt()); + + + if (playerCharacter.region != null && !loginData) { + Building building = Regions.GetBuildingForRegion(playerCharacter.region); + + if (building == null) { + writer.putInt(0); + writer.putInt(0); + } else { + writer.putInt(Enum.GameObjectType.Building.ordinal()); + writer.putInt(building.getObjectUUID()); + } + + } else { + writer.putInt(0); + writer.putInt(0); + } + + + writer.put((byte) 0); + writer.put((byte) 0); + writer.put((byte) 0); + writer.putInt(0); + writer.put((byte) 0); + writer.put((byte) 0); + writer.put((byte) 0); + +// writer.putInt(0); +// writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + + if (!playerCharacter.isAlive() && otherPlayer) { + writer.putInt(0); + writer.putInt(0); + } + + + //TODO FIGURE OUT THE REAL SEARLIZATION FOR NEXT 2 SHORTS? + writer.putInt(playerCharacter.getSkinColor()); // Skin Color + writer.putFloat(20); + writer.put((byte) 0); //Unknown + + //unknown object + writer.putInt(0); + writer.putInt(0); + + //unknown type + writer.putInt(0); + //0x4080 should be the next short here, instead it wraps 0's down their in for loops.. seriously.. who wrote playerCharacter shit. + // playerCharacter aint right! + // ByteBufferUtils.putString(writer, playerCharacter.guild.getName()); + // writer.putInt(playerCharacter.getGuild().getUUID()); + // ByteBufferUtils.putString(writer, playerCharacter.guild.getNation().getName()); + // writer.putInt(playerCharacter.getGuild().getNation().getUUID()); + Guild.serializeForClientMsg(playerCharacter.getGuild(), writer, playerCharacter, false); + + //Send Tokens for race/class/promotion (disciplines?) + if (playerCharacter.getPromotionClass() != null) + writer.putInt(3); + else + writer.putInt(2); + writer.putInt(playerCharacter.getRace().getToken()); + writer.putInt(playerCharacter.getBaseClass().getToken()); + if (playerCharacter.getPromotionClass() != null) + writer.putInt(playerCharacter.getPromotionClass().getToken()); + + writer.putFloat(playerCharacter.getAltitude()); // altitude? + writer.putFloat(playerCharacter.getAltitude()); // altitude? + writer.put((byte) 0); // End Datablock byte + + writer.putFloat(playerCharacter.healthMax); + writer.putFloat(playerCharacter.health.get()); + + writer.put((byte) 0); // End Datablock byte + //size + + + if (loginData) { + writer.putInt(0); + } else { + int indexPosition = writer.position(); + writer.putInt(0); //placeholder for item cnt + int total = 0; + // Logger.info("",""+ playerCharacter.getEffects().size()); + for (Effect eff : playerCharacter.getEffects().values()) { + if (eff.getPower() == null && otherPlayer) + continue; + if (eff.getPower() != null && eff.getPower().token == 429506619) // Oblivion's Caress + continue; + if (!eff.serializeForLoad(writer)) + continue; + ++total; + + } + + writer.putIntAt(total, indexPosition); + } + + if (otherPlayer) { + writer.put((byte) 0); // End Datablock Byte + return; + + } + + //made up for sendalleffects + //writer.putInt(0); // Pad + //writer.put((byte) 0); // End Datablock byte + writer.putInt(playerCharacter.getUnusedStatPoints()); + writer.putInt(playerCharacter.getLevel()); + writer.putInt(playerCharacter.getExp() + playerCharacter.getOverFlowEXP()); + writer.putFloat(playerCharacter.getManaMax()); + writer.putFloat(playerCharacter.mana.get()); + writer.putFloat(playerCharacter.getStaminaMax()); + writer.putFloat(playerCharacter.stamina.get()); + writer.putInt(playerCharacter.getAtrHandOne()); + writer.putInt(playerCharacter.getAtrHandTwo()); + writer.putInt(playerCharacter.getDefenseRating()); + + if (MBServerStatics.POWERS_DEBUG) //debug mode, grant lots of trains + writer.putInt(1000); + else + writer.putInt(playerCharacter.trainsAvailable.get()); + + /* + * Skills + */ + if (loginData) + writer.putInt(0); // Skip skills + else { + writer.putInt(playerCharacter.getSkills().size()); + Iterator it = playerCharacter.getSkills().keySet().iterator(); + while (it.hasNext()) { + String name = it.next(); + CharacterSkill.serializeForClientMsg(playerCharacter.getSkills().get(name), writer); + } + } + + /* + * Powers + */ + if (loginData) + writer.putInt(0); // Skip Powers + else if (MBServerStatics.POWERS_DEBUG) //debug mode, grant all powers + PowersManager.testPowers(writer); + else { + writer.putInt(playerCharacter.getPowers().size()); + for (CharacterPower sp : playerCharacter.getPowers().values()) { + CharacterPower.serializeForClientMsg(sp, writer); + } + } + + /* + * Inventory + */ + if (loginData) { + writer.putInt(0); // Skip Inventory + writer.putInt(playerCharacter.getInventoryCapacity()); // Inventory Capacity + + } else { + ArrayList inv = playerCharacter.getCharItemManager().getInventory(true); + Item.putList(writer, inv, false, playerCharacter.getObjectUUID()); + writer.putInt(playerCharacter.getInventoryCapacityRemaining()); + } + + /* + * Bank + */ + if (loginData) { + writer.putInt(0); // Skip Bank + writer.putInt(AbstractCharacter.getBankCapacity()); // Bank Capacity + + } else { + ArrayList bank = playerCharacter.getCharItemManager().getBank(); + + Item.putList(writer, bank, false, playerCharacter.getObjectUUID()); + writer.putInt(playerCharacter.getBankCapacityRemaining()); + } + //load player friends. + if (loginData) + writer.putInt(0); + else { + HashSet friendMap = PlayerFriends.PlayerFriendsMap.get(playerCharacter.getObjectUUID()); + if (friendMap == null) + writer.putInt(0); + else { + writer.putInt(friendMap.size()); + for (int friendID : friendMap) { + PlayerCharacter friend = getFromCache(friendID); + //shouldn't get here, but if null serialize blank friend. + if (friend == null) { + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + } else { + writer.putInt(friend.getObjectType().ordinal()); + writer.putInt(friend.getObjectUUID()); + writer.putString(friend.getName()); + boolean online = SessionManager.getPlayerCharacterByID(friend.getObjectUUID()) != null ? true : false; + writer.putInt(online ? 0 : 1); + writer.putInt(friend.friendStatus.ordinal()); + } + + } + } + } + + + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + writer.putInt(0); + + writer.putShort((short) 0); + writer.put((byte) 0); + // playerCharacter is for send self in enter world (full character) + if (!loginData && !freshChar) { + int size = playerCharacter.getRecycleTimers().size(); + writer.putInt(size); + if (size > 0) + for (int token : playerCharacter.getRecycleTimers().keySet()) { + + JobContainer frtj = playerCharacter.getRecycleTimers().get(token); + long timeLeft = frtj.timeOfExection() - System.currentTimeMillis(); + writer.putInt(token); + writer.putInt((int) timeLeft / 1000); + } + DateTime enterWorld = new DateTime(playerCharacter.getTimestamps().get("EnterWorld")); + writer.putDateTime(enterWorld); + + writer.putInt(0x49EF1E98); //DUnno what playerCharacter is. + writer.putFloat(DateTime.now().hourOfDay().get()); //daylight in float. + writer.putFloat(6); //interval of light to change per game hour //float + //writer.putInt(1637194901); //playerCharacter is actually an opcode taht is in recordings, no clue what it is, dumped it and it changes nothing + } else { + writer.put((byte) 0); //added to compensate the cooldown check. + + //add server up or down + int serverUp = LoginServer.worldServerRunning ? 1 : 0; + + if (playerCharacter.getAccount() == null) + serverUp = 0; + + if ((playerCharacter.getAccount().status.equals(Enum.AccountStatus.ADMIN) == false) && + (playerCharacter.getAccount().status.equals(WorldServer.worldAccessLevel) == false)) + serverUp = 0; + + writer.putInt(serverUp); + writer.putInt(0); // effects, not sure used by players + writer.put((byte) 0); // End Player Datablock + } + + } + + public static PlayerCharacter generatePCFromCommitNewCharacterMsg(Account a, CommitNewCharacterMsg msg, ClientConnection clientConnection) { + + String firstName = msg.getFirstName().trim(); + String lastName = msg.getLastName().trim(); + + if (firstName.length() < 3) { + LoginServerMsgHandler.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_FIRSTNAME_MUST_BE_LONGER, + clientConnection); + return null; + } + + // Ensure names are below required length + if (firstName.length() > 15 || lastName.length() > 15) { + LoginServerMsgHandler.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_FIRSTANDLAST_MUST_BE_SHORTER, + clientConnection); + return null; + } + + // Check if firstname is valid + if (MiscUtils.checkIfFirstNameInvalid(firstName)) { + LoginServerMsgHandler.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_PLEASE_CHOOSE_ANOTHER_FIRSTNAME, + clientConnection); + return null; + } + + // Check if last name is valid + if (MiscUtils.checkIfLastNameInvalid(lastName)) { + LoginServerMsgHandler.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_LASTNAME_UNAVAILABLE, + clientConnection); + return null; + } + + // Verify Race + int raceID = msg.getRace(); + + if(raceID == 0) + raceID = 1999; + + Race race = Race.getRace(raceID); + + if (race == null) { + Logger.info("Invalid RaceID: " + raceID); + return null; + } + + // Verify BaseClass Object. + int baseClassID = msg.getBaseClass(); + BaseClass baseClass = DbManager.BaseClassQueries.GET_BASE_CLASS(baseClassID); + + if (baseClass == null) { + Logger.info("Invalid BaseClasID: " + baseClassID); + return null; + } + + // Verify Race/baseClass combo. + boolean valid = false; + + for (BaseClass bc : race.getValidBaseClasses()) { + + if (bc.getObjectUUID() == baseClassID) { + valid = true; + break; + } + } + + if (!valid) { + Logger.info("Invalid BaseClass/Race Combo"); + return null; + } + + // Verify HairStyle/BeardStyle/SkinColor/HairColor/BeardColor + int hairStyleID = msg.getHairStyle(); + int beardStyleID = msg.getBeardStyle(); + int skinColorID = msg.getSkinColor(); + int hairColorID = msg.getHairColor(); + int beardColorID = msg.getBeardColor(); + + if(raceID != 1999) { + if (!race.isValidHairStyle(hairStyleID)) { + Logger.info("Invalid HairStyleID: " + hairStyleID + " for race: " + race.getName()); + return null; + } + + if (!race.isValidSkinColor(skinColorID)) { + Logger.info("Invalid skinColorID: " + skinColorID + " for race: " + race.getName()); + return null; + } + + if (!race.isValidHairColor(hairColorID)) { + Logger.info("Invalid hairColorID: " + hairColorID + " for race: " + race.getName()); + return null; + } + + if (!race.isValidBeardColor(beardColorID)) { + Logger.info("Invalid beardColorID: " + beardColorID + " for race: " + race.getName()); + return null; + } + } + // Get stat modifiers + int strMod = msg.getStrengthMod(); + int dexMod = msg.getDexterityMod(); + int conMod = msg.getConstitutionMod(); + int intMod = msg.getIntelligenceMod(); + int spiMod = msg.getSpiritMod(); + + + if (intMod < -5 || dexMod < -5 || conMod < -5 || strMod < -5 || spiMod < -5) { + Logger.error("NEGATIVE STAT CHEAT ATTEMPTED! ACCOUNT: " + a.getUname() + "(" + a.getObjectUUID() + ") IP ADDRESS: " + clientConnection.getClientIpAddress()); + return null; + } + + // calculate current stats: + short strCur = (short) (race.getStrStart() + baseClass.getStrMod() + strMod); + short dexCur = (short) (race.getDexStart() + baseClass.getDexMod() + dexMod); + short conCur = (short) (race.getConStart() + baseClass.getConMod() + conMod); + short intCur = (short) (race.getIntStart() + baseClass.getIntMod() + intMod); + short spiCur = (short) (race.getSpiStart() + baseClass.getSpiMod() + spiMod); + + // calculate max stats: + short strMax = race.getStrMax(); + short dexMax = race.getDexMax(); + short conMax = race.getConMax(); + short intMax = race.getIntMax(); + short spiMax = race.getSpiMax(); + + // Verify not too many runes applied + int numRunes = msg.getNumRunes(); + + if (numRunes > 16) { + Logger.info("Too many Runes applied"); + return null; + } + + // Get Runes + // ArrayList characterRunesUsed = new ArrayList(); + // ArrayList subtypesUsed = new ArrayList(); + int remainingPoints = race.getStartingPoints() - strMod - dexMod - conMod - intMod - spiMod; + + int[] characterRunes = msg.getRunes(); + + HashSet usedRunesSubType = new HashSet<>(); + HashSet usedRunes = new HashSet<>(); + + // So that all the penalties can be added at the end. + ConcurrentHashMap penalties = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + + penalties.put("StrCur", 0); + penalties.put("StrMax", 0); + penalties.put("DexCur", 0); + penalties.put("DexMax", 0); + penalties.put("ConCur", 0); + penalties.put("ConMax", 0); + penalties.put("IntCur", 0); + penalties.put("IntMax", 0); + penalties.put("SpiCur", 0); + penalties.put("SpiMax", 0); + + PriorityQueue> orderedRunes = new PriorityQueue<>(14, + new Comparator>() { + + @Override + public int compare(Map.Entry o1, Map.Entry o2) { + return o1.getKey() - o2.getKey(); + } + }); + + // Figure out which Runes we are adding. + for (int i : characterRunes) { + // Zero skip + if (i == 0) + continue; + + // Skip the Race and BaseClass runes... already dealt with. + if (i == raceID || i == baseClassID) + continue; + + RuneBase runeBase = RuneBase.getRuneBase(i); + + // Null check + if (runeBase == null) { + Logger.info("GOM returned NULL RuneBase"); + return null; + } + + // Validate Rune against Race + if(raceID != 1999) { + if (!race.isAllowedRune(runeBase)) { + Logger.info("Trait Not valid for Race"); + return null; + } + } + // Validate BaseClass against Race + if (!baseClass.isAllowedRune(runeBase)) { + Logger.info("Trait Not valid for BaseClass"); + return null; + } + + int previous_size = usedRunes.size(); + int previous_subtype = usedRunesSubType.size(); + + usedRunes.add(runeBase); + usedRunesSubType.add(runeBase.getSubtype()); + + // Duplicate Rune check + if (usedRunes.size() <= previous_size) { + Logger.info("Duplicate RuneBase"); + return null; + } + + // Duplicate Subtype check + if (runeBase.getSubtype() != 0 && usedRunesSubType.size() <= previous_subtype) { + Logger.info("Duplicate RuneBase Subtype"); + return null; + } + + int maxValue = 0; + + // Every attempt is made to load MIN_NEEDED_ATTRIBUTES first. + + if (runeBase.getAttrs() != null) + for (RuneBaseAttribute rba : runeBase.getAttrs()) { + if (rba.getAttributeID() == MBServerStatics.RUNE_STR_MIN_NEEDED_ATTRIBUTE_ID + || rba.getAttributeID() == MBServerStatics.RUNE_DEX_MIN_NEEDED_ATTRIBUTE_ID + || rba.getAttributeID() == MBServerStatics.RUNE_CON_MIN_NEEDED_ATTRIBUTE_ID + || rba.getAttributeID() == MBServerStatics.RUNE_INT_MIN_NEEDED_ATTRIBUTE_ID + || rba.getAttributeID() == MBServerStatics.RUNE_SPI_MIN_NEEDED_ATTRIBUTE_ID) { + maxValue = rba.getModValue(); + if (runeBase.getName().equals("Giant's Blood")) + maxValue = 45; // Take care of the Giant's Blood special + // case. + break; + } + } + + orderedRunes.add(new AbstractMap.SimpleEntry<>(maxValue, runeBase)); + } + + while (orderedRunes.size() > 0) { + RuneBase rb = orderedRunes.remove().getValue(); + ArrayList attrs = rb.getAttrs(); + + if (attrs != null) + for (RuneBaseAttribute abr : attrs) { + + int attrID = abr.getAttributeID(); + int value = abr.getModValue(); + + switch (attrID) { + case MBServerStatics.RUNE_COST_ATTRIBUTE_ID: + + Logger.info("Bought " + rb.getName() + " for " + value + " points. " + + (remainingPoints - value) + " left."); + + if ((remainingPoints - value) >= 0) { + remainingPoints -= value; + continue; + } + Logger.info("Not enough points left"); + return null; + case MBServerStatics.RUNE_STR_MIN_NEEDED_ATTRIBUTE_ID: + + if (strCur >= value) + continue; + + Logger.info("STR fails to meet Rune Minimum --> " + rb.getName()); + return null; + case MBServerStatics.RUNE_DEX_MIN_NEEDED_ATTRIBUTE_ID: + + if (dexCur >= value) + continue; + + Logger.info("DEX fails to meet Rune Minimum --> " + rb.getName()); + return null; + case MBServerStatics.RUNE_CON_MIN_NEEDED_ATTRIBUTE_ID: + + if (conCur >= value) + continue; + + Logger.info("CON fails to meet Rune Minimum --> " + rb.getName()); + return null; + case MBServerStatics.RUNE_INT_MIN_NEEDED_ATTRIBUTE_ID: + + if (intCur >= value) + continue; + + Logger.info("INT fails to meet Rune Minimum --> " + rb.getName()); + return null; + case MBServerStatics.RUNE_SPI_MIN_NEEDED_ATTRIBUTE_ID: + + if (spiCur >= value) + continue; + + Logger.info("SPI fails to meet Rune Minimum --> " + rb.getName()); + return null; + case MBServerStatics.RUNE_STR_ATTRIBUTE_ID: + + if (value < 0) + penalties.put("StrCur", (penalties.get("StrCur") + value)); + else + strCur += value; + continue; + + case MBServerStatics.RUNE_DEX_ATTRIBUTE_ID: + if (value < 0) + penalties.put("DexCur", (penalties.get("DexCur") + value)); + else + dexCur += value; + continue; + case MBServerStatics.RUNE_CON_ATTRIBUTE_ID: + if (value < 0) + penalties.put("ConCur", (penalties.get("ConCur") + value)); + else + conCur += value; + continue; + case MBServerStatics.RUNE_INT_ATTRIBUTE_ID: + if (value < 0) + penalties.put("IntCur", (penalties.get("IntCur") + value)); + else + intCur += value; + continue; + case MBServerStatics.RUNE_SPI_ATTRIBUTE_ID: + if (value < 0) + penalties.put("SpiCur", (penalties.get("SpiCur") + value)); + else + spiCur += value; + continue; + case MBServerStatics.RUNE_STR_MAX_ATTRIBUTE_ID: + if (value < 0) + penalties.put("StrMax", (penalties.get("StrMax") + value)); + else + strMax += value; + continue; + case MBServerStatics.RUNE_DEX_MAX_ATTRIBUTE_ID: + if (value < 0) + penalties.put("DexMax", (penalties.get("DexMax") + value)); + else + dexMax += value; + continue; + case MBServerStatics.RUNE_CON_MAX_ATTRIBUTE_ID: + if (value < 0) + penalties.put("ConMax", (penalties.get("ConMax") + value)); + else + conMax += value; + continue; + case MBServerStatics.RUNE_INT_MAX_ATTRIBUTE_ID: + if (value < 0) + penalties.put("IntMax", (penalties.get("IntMax") + value)); + else + intMax += value; + continue; + case MBServerStatics.RUNE_SPI_MAX_ATTRIBUTE_ID: + if (value < 0) + penalties.put("SpiMax", (penalties.get("SpiMax") + value)); + else + spiMax += value; + continue; + + default: + Logger.info("Unknown ATTRIBUTE_ID while checking RuneBaseAttributes: " + attrID); + return null; + } + } + } + + // Add in all of the penalties. + strCur += penalties.get("StrCur"); + strMax += penalties.get("StrMax"); + dexCur += penalties.get("DexCur"); + dexMax += penalties.get("DexMax"); + conCur += penalties.get("ConCur"); + conMax += penalties.get("ConMax"); + intCur += penalties.get("IntCur"); + intMax += penalties.get("IntMax"); + spiCur += penalties.get("SpiCur"); + spiMax += penalties.get("SpiMax"); + + int kitID = msg.getKit(); + + // get the correctKit + int raceClassID; + if(raceID != 1999){ + raceClassID = Kit.GetKitIDByRaceClass(raceID, baseClassID); + }else{ + raceClassID = Kit.GetKitIDByRaceClass(2011, baseClassID); + } + ArrayList allKits = Kit.RaceClassIDMap.get(raceClassID); + + + Kit kit = null; + + for (Kit k : allKits) { + if (k.getKitNumber() == kitID) { + kit = k; + break; + } + } + + if (kit == null) { + Logger.info("Unable to find matching kitID: " + kitID); + return null; + } + + byte runningTrains = 0; + PlayerCharacter playerCharacter; + + //Synchronized block to allow exclusive access when confirming + //uniqueness of FirstName and subsequently saving the new record + //to the database with that FirstName + synchronized (PlayerCharacter.FirstNameLock) { + // Test if FirstName already exists. + // This must be the very last check before calling the + // DB to create the character record + if (DbManager.PlayerCharacterQueries.IS_CHARACTER_NAME_UNIQUE(firstName) == false) { + LoginServerMsgHandler.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_FIRSTNAME_UNAVAILABLE, + clientConnection); + return null; + } + if(raceID == 1999){ + hairStyleID = 0; + beardStyleID = 0; + skinColorID = 0; + hairColorID = 0; + beardColorID = 0; + } + + // Make PC + PlayerCharacter pcWithoutID = new PlayerCharacter(firstName, lastName, (short) strMod, (short) dexMod, (short) conMod, + (short) intMod, (short) spiMod, Guild.getErrantGuild(), runningTrains, a, race, baseClass, (byte) skinColorID, (byte) hairColorID, + (byte) beardColorID, (byte) beardStyleID, (byte) hairStyleID); + + try { + playerCharacter = DbManager.PlayerCharacterQueries.ADD_PLAYER_CHARACTER(pcWithoutID); + } catch (Exception e) { + Logger.error("generatePCFromCommitNewCharacterMsg", "An error occurred while saving new PlayerCharacter to DB", e); + return null; + } + + if (playerCharacter == null) { + Logger.info("GOM Failed to create PlayerCharacter"); + return null; + } + + } // END synchronized(FirstNameLock) + + // Add creation runes + for (RuneBase rb : usedRunes) { + CharacterRune runeWithoutID = new CharacterRune(rb, playerCharacter.getObjectUUID()); + CharacterRune characterRune; + try { + characterRune = DbManager.CharacterRuneQueries.ADD_CHARACTER_RUNE(runeWithoutID); + } catch (Exception e) { + characterRune = null; + } + + if (characterRune == null) { + playerCharacter.deactivateCharacter(); + Logger.info("GOM Failed to create CharacterRune"); + return null; + } + + playerCharacter.addRune(characterRune); + } + + if (hairStyleID != 0) { + // Create Hair + Item tempHair = new Item(ItemBase.getItemBase(hairStyleID), playerCharacter.getObjectUUID(), Enum.OwnerType.PlayerCharacter, + (byte) 0, (byte) 0, (short) 1, (short) 1, false, false, Enum.ItemContainerType.EQUIPPED, + (byte) MBServerStatics.SLOT_HAIRSTYLE, new ArrayList<>(), ""); + + Item hair; + + try { + hair = DbManager.ItemQueries.ADD_ITEM(tempHair); + } catch (Exception e) { + hair = null; + } + + if (hair == null) { + playerCharacter.deactivateCharacter(); + Logger.info("GameObjectManager failed to create Hair:" + hairStyleID + " in Slot:" + + MBServerStatics.SLOT_HAIRSTYLE); + return null; + } + } + + if (beardStyleID != 0) { + // Create Beard + Item tempBeard = new Item(ItemBase.getItemBase(beardStyleID), playerCharacter.getObjectUUID(), Enum.OwnerType.PlayerCharacter, + (byte) 0, (byte) 0, (short) 1, (short) 1, false, false, Enum.ItemContainerType.EQUIPPED, + (byte) MBServerStatics.SLOT_BEARDSTYLE, new ArrayList<>(), ""); + Item beard; + try { + beard = DbManager.ItemQueries.ADD_ITEM(tempBeard); + } catch (Exception e) { + beard = null; + } + + if (beard == null) { + playerCharacter.deactivateCharacter(); + Logger.info("GameObjectManager failed to create Beard:" + beardStyleID + " in Slot:" + + MBServerStatics.SLOT_BEARDSTYLE); + return null; + } + } + // Create items from Kit and equip on character. + try { + kit.equipPCwithKit(playerCharacter); + } catch (Exception e) { + Logger.info("Unable to find KIT ID for Race: " + raceID + "||" + "Class:" + baseClassID); + playerCharacter.deactivateCharacter(); + return null; + } + + // Get any new skills that belong to the player + playerCharacter.calculateSkills(); + + a.setLastCharacter(playerCharacter.getObjectUUID()); + playerCharacter.getCharItemManager().load(); + + playerCharacter.activateCharacter(); + + return playerCharacter; + } + + public static boolean isIgnoreListFull() { + return false; //Why were we setting a limit on ignores? - + //return (ignoredPlayerIDs.size() >= MBServerStatics.IGNORE_LIST_MAX); + } + + public static boolean isIgnorable() { + return true; + // // if (account == null) return false; + // if (account.getAccessLevel() > 0) { + // return false; + // } + // return true; + } + + /** + * @ Initialize player upon creation + */ + public static void initializePlayer(PlayerCharacter player) { + + if (player.initialized) + return; + // Logger.info("", " Initializing " + player.getCombinedName()); + player.skills = DbManager.CharacterSkillQueries.GET_SKILLS_FOR_CHARACTER(player); + player.powers = player.initializePowers(); + + + if (ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER)) + player.setLoc(player.getBindLoc()); + player.endLoc = Vector3fImmutable.ZERO; + + //get level based on experience + player.level = (short) Experience.getLevel(player.getExp()); + + player.setHealth(999999f); + player.mana.set(999999f); + player.stamina.set(999999f); + player.bonuses = new PlayerBonuses(player); + PlayerBonuses.InitializeBonuses(player); + player.setResists(new Resists(player)); + player.getCharItemManager().load(); + + if (ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER)) { + + //CharacterSkill.updateAllBaseAmounts(this); + CharacterPower.grantTrains(player); + + // calculate skills. Make sure none are missing. + AbstractCharacter.runBonusesOnLoad(player); + + InitializeSkillsOnLoad(player); + + //apply all bonuses + player.recalculatePlayerStats(true); + player.trainsAvailable.set(CharacterSkill.getTrainsAvailable(player)); + + if (player.trainsAvailable.get() < 0) + player.recalculateTrains(); + + //this.resists.calculateResists(this); + player.newChar = true; + + //check current guild valid for player + checkGuildStatus(player); + + player.setHealth(player.getHealthMax()); + player.mana.set(player.getManaMax()); + player.stamina.set(player.getStaminaMax()); + } else + player.setBindLoc(Vector3fImmutable.ZERO); + + player.initialized = true; + + String lastAscii = player.getLastName().replaceAll("[^\\p{ASCII}]", ""); + player.asciiLastName = lastAscii.equals(player.getLastName()); + } + + public static void recalculatePlayerStatsOnLoad(PlayerCharacter pc) { + + //calculate base stats + pc.calculateBaseStats(); + + //calculate base skills + CharacterSkill.updateAllBaseAmounts(pc); + pc.calculateModifiedStats(); + + //calculate modified skills + CharacterSkill.updateAllModifiedAmounts(pc); + + + //calculate modified stats + + + //calculate ATR, damage and defense + pc.calculateAtrDefenseDamage(); + + //calculate movement bonus + calculateSpeedMod(pc); + + // recalculate Max Health/Mana/Stamina + pc.calculateMaxHealthManaStamina(); + + // recalculate Resists + Resists.calculateResists(pc); + + } + + public static boolean hideNonAscii() { + + return false; + } + + public static float getDexPenalty(Item armor) { + if (armor == null) + return 0f; + ItemBase ab = armor.getItemBase(); + if (ab == null) + return 0f; + return ab.getDexPenalty(); + } + + public static float getModifiedAmount(CharacterSkill skill) { + if (skill == null) + return 0f; + return skill.getModifiedAmount(); + } + + public static void InitializeSkillsOnLoad(PlayerCharacter pc) { + try { + { + + //see if any new skills or powers granted + CharacterSkill.calculateSkills(pc); + + // calculate granted Trains in powers. + CharacterPower.grantTrains(pc); + + //see if any new powers unlocked from previous check + CharacterPower.calculatePowers(pc); + } + } catch (Exception e) { + Logger.error(e.getMessage()); + } + + } + + public static String getFirstName(int tableId) { + + PlayerCharacter player; + + if (tableId == 0) + return ""; + + player = (PlayerCharacter) DbManager.getObject(Enum.GameObjectType.PlayerCharacter, tableId); + + return player.getFirstName(); + } + + public static PlayerCharacter getFromCache(int id) { + return (PlayerCharacter) DbManager.getFromCache(Enum.GameObjectType.PlayerCharacter, id); + } + + public static PlayerCharacter getByFirstName(String name) { + + PlayerCharacter returnPlayer = null; + for (AbstractGameObject ago : DbManager.getList(Enum.GameObjectType.PlayerCharacter)) { + PlayerCharacter cachePlayer = (PlayerCharacter) ago; + if (!name.equalsIgnoreCase(cachePlayer.getFirstName())) + continue; + if (cachePlayer.isDeleted()) + continue; + returnPlayer = cachePlayer; + break; + } + + return returnPlayer; + } + + public static PlayerCharacter getPlayerCharacter(int uuid) { + + PlayerCharacter outPlayer; + + outPlayer = DbManager.PlayerCharacterQueries.GET_PLAYER_CHARACTER(uuid); + + if (outPlayer != null) + return outPlayer; + + return (PlayerCharacter) DbManager.getFromCache(Enum.GameObjectType.PlayerCharacter, uuid); + } + + public static int GetPlayerRealmTitle(PlayerCharacter player) { + + if (player.getGuild().isEmptyGuild()) + return 0; + if (!player.getGuild().isGuildLeader(player.getObjectUUID())) + return 0; + if (player.getGuild().getOwnedCity() == null) + return 10; + if (player.getGuild().getOwnedCity().getRealm() == null) + return 10; + if (player.getGuild().getOwnedCity().getRealm().getRulingCity() == null) + return 10; + + if (player.getGuild().getOwnedCity().getRealm().getRulingCity().getObjectUUID() != player.getGuild().getOwnedCity().getObjectUUID()) + return 10; + int realmTitle = 1; + if (player.getGuild().getSubGuildList() == null || player.getGuild().getSubGuildList().isEmpty()) + return 11; + for (Guild subGuild : player.getGuild().getSubGuildList()) { + if (subGuild.getOwnedCity() == null) + continue; + if (subGuild.getOwnedCity().getRealm() == null) + continue; + if (subGuild.getOwnedCity().getRealm().getRulingCity() == null) + continue; + if (subGuild.getOwnedCity().getRealm().getRulingCity().getObjectUUID() != subGuild.getOwnedCity().getObjectUUID()) + continue; + realmTitle++; + } + + if (realmTitle < 3) + return 11; + else if (realmTitle < 5) + return 12; + else + return 13; + } + + public static void UpdateClientPlayerRank(PlayerCharacter pc) { + if (pc == null) + return; + boolean disable = true; + + if (disable) + return; + UpdateCharOrMobMessage ucm = new UpdateCharOrMobMessage(pc, 2, pc.getRank()); + DispatchMessage.sendToAllInRange(pc, ucm); + } + + public static void GroundPlayer(PlayerCharacter groundee) { + if (groundee.getDesiredAltitude() == 0 && groundee.getAltitude() == 0) + return; + groundee.setAltitude(groundee.getAltitude()); + groundee.setDesiredAltitude(0); + groundee.setTakeOffTime(System.currentTimeMillis()); + + ChangeAltitudeMsg msg = ChangeAltitudeMsg.GroundPlayerMsg(groundee); + // force a landing + DispatchMessage.dispatchMsgToInterestArea(groundee, msg, Enum.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + + } + + public static boolean CanBreathe(PlayerCharacter breather) { + try { + if (isFlying(breather)) + return true; + Zone zone = ZoneManager.findSmallestZone(breather.getLoc()); + + if (zone.getSeaLevel() != 0) { + + float localAltitude = breather.getLoc().y; + + + if (localAltitude + breather.getCharacterHeight() < zone.getSeaLevel() - 2) + return false; + + if (breather.isMoving()) { + if (localAltitude + breather.getCharacterHeight() < zone.getSeaLevel()) + return false; + } + } else { + if (breather.getLoc().y + breather.getCharacterHeight() < -2) + return false; + + if (breather.isMoving()) { + if (breather.getLoc().y + breather.getCharacterHeight() < 0) + return false; + } + } + + + } catch (Exception e) { + Logger.info(breather.getName() + e); + } + + + return true; + } + + public static boolean enterWater(PlayerCharacter enterer) { + + try { + if (isFlying(enterer)) + return false; + + + Zone zone = ZoneManager.findSmallestZone(enterer.getLoc()); + + if (zone.getSeaLevel() != 0) { + + float localAltitude = enterer.getLoc().y + enterer.getCharacterHeight(); + + + if (localAltitude < zone.getSeaLevel()) + return true; + } else { + if (enterer.getLoc().y + enterer.getCharacterHeight() < 0) + return true; + } + } catch (Exception e) { + Logger.info(enterer.getName() + e); + } + + return false; + + } + + public static boolean LeaveWater(PlayerCharacter leaver) { + + try { + + + Zone zone = ZoneManager.findSmallestZone(leaver.getLoc()); + + float leaveWater = leaver.centerHeight; + + if (leaver.isMoving()) + leaveWater = 1f; + + + if (zone.getSeaLevel() != 0) { + + float localAltitude = leaver.getLoc().y; + + + if (localAltitude + leaveWater < zone.getSeaLevel()) + return false; + } else { + if (leaver.getLoc().y + leaveWater < 0) + return false; + } + } catch (Exception e) { + Logger.info(leaver.getName() + e); + } + + return true; + } + + public static boolean CanBindToBuilding(PlayerCharacter player, int buildingID) { + if (buildingID == 0) + return false; + + Building bindBuilding = BuildingManager.getBuildingFromCache(buildingID); + + if (bindBuilding == null) + return false; + + if (!BuildingManager.playerCanManage(player, bindBuilding)) + return false; + + return true; + } + + public static void forceRespawn(PlayerCharacter sourcePlayer) throws MsgSendException { + + if (sourcePlayer == null) + return; + try { + sourcePlayer.getClientConnection().disconnect(); + } catch (Exception e) { + + } + + } + + public static void unboxPlayer(PlayerCharacter player){ + String machineID = player.getClientConnection().machineID; + ArrayList sameMachine = new ArrayList<>(); + for(PlayerCharacter pc : SessionManager.getAllActivePlayerCharacters()){ + if(!pc.equals(player) && pc.isActive() && pc.isEnteredWorld() && pc.getClientConnection().machineID.equals(machineID)){ + sameMachine.add(pc); + } + } + + for(PlayerCharacter pc : sameMachine) + pc.isBoxed = true; + + player.isBoxed = false; + if(player.containsEffect(1672601862)) { + player.removeEffectBySource(Enum.EffectSourceType.DeathShroud,41,false); + } + + } + + public static boolean checkIfBoxed(PlayerCharacter player){ + if(ConfigManager.MB_WORLD_TESTMODE.getValue().equals("true")) { + return false; + } + try { + String machineID = player.getClientConnection().machineID; + ArrayList sameMachine = new ArrayList<>(); + for (PlayerCharacter pc : SessionManager.getAllActivePlayerCharacters()) { + if (!pc.equals(player) && pc.isActive() && pc.isEnteredWorld() && pc.getClientConnection().machineID.equals(machineID)) { + sameMachine.add(pc); + } + } + + boolean boxed = false; + for (PlayerCharacter pc : sameMachine) + if (!pc.isBoxed) + boxed = true; + + return boxed; + }catch(Exception e){ + return false; + } + } + + public static void setGuildTitle(PlayerCharacter playerCharacter, int value) { + if (GuildStatusController.getTitle(playerCharacter.getGuildStatus()) == value) + return; + DbManager.PlayerCharacterQueries.SET_GUILD_TITLE(playerCharacter, value); + GuildStatusController.setTitle(playerCharacter.getGuildStatus(), value); + } + + public static void setFullMember(PlayerCharacter playerCharacter, boolean value) { + if (GuildStatusController.isFullMember(playerCharacter.getGuildStatus()) == value) + return; + DbManager.PlayerCharacterQueries.SET_FULL_MEMBER(playerCharacter, value); + GuildStatusController.setFullMember(playerCharacter.getGuildStatus(), value); + } + + public static void setRecruiter(PlayerCharacter playerCharacter, boolean value) { + if (GuildStatusController.isRecruiter(playerCharacter.getGuildStatus()) == value) + return; + DbManager.PlayerCharacterQueries.SET_RECRUITER(playerCharacter, value); + GuildStatusController.setRecruiter(playerCharacter.getGuildStatus(), value); + } + + public static void setTaxCollector(PlayerCharacter playerCharacter, boolean value) { + if (GuildStatusController.isTaxCollector(playerCharacter.getGuildStatus()) == value) + return; + DbManager.PlayerCharacterQueries.SET_TAX_COLLECTOR(playerCharacter, value); + GuildStatusController.setTaxCollector(playerCharacter.getGuildStatus(), value); + } + + public static void setInnerCouncil(PlayerCharacter playerCharacter, boolean value) { + + // dont update if its the same. + if (GuildStatusController.isInnerCouncil(playerCharacter.getGuildStatus()) == value) + return; + + DbManager.PlayerCharacterQueries.SET_INNERCOUNCIL(playerCharacter, value); + GuildStatusController.setInnerCouncil(playerCharacter.getGuildStatus(), value); + } + + public static void setGuildLeader(PlayerCharacter playerCharacter, boolean value) { + if (GuildStatusController.isGuildLeader(playerCharacter.getGuildStatus()) == value) + return; + + GuildStatusController.setGuildLeader(playerCharacter.getGuildStatus(), value); + if (value == true) { + setInnerCouncil(playerCharacter, true); + setFullMember(playerCharacter, true); + } + } + + //END -> Guild Status Interface + public static void resetGuildStatuses(PlayerCharacter playerCharacter) { + setInnerCouncil(playerCharacter, false); + setFullMember(playerCharacter, false); + setGuildTitle(playerCharacter, 0); + setTaxCollector(playerCharacter, false); + setRecruiter(playerCharacter, false); + setGuildLeader(playerCharacter, false); + } + + public static void setEnteredWorld(PlayerCharacter playerCharacter, boolean enteredWorld) { + playerCharacter.enteredWorld = enteredWorld; + } + + public static boolean isLastSwimming(PlayerCharacter playerCharacter) { + return playerCharacter.lastSwimming; + } + + public static void teleport(PlayerCharacter playerCharacter, final Vector3fImmutable targetLoc) { + + Regions targetRegion = Regions.GetRegionForTeleport(targetLoc); + playerCharacter.locationLock.writeLock().lock(); + + try { + MovementManager.translocate(playerCharacter, targetLoc, targetRegion); + } catch (Exception e) { + Logger.error(e); + } finally { + playerCharacter.locationLock.writeLock().unlock(); + } + } + + public static float getBargain(PlayerCharacter playerCharacter) { + float bargain = 0; + + CharacterSkill bargainSkill = playerCharacter.getSkills().get(Enum.CharacterSkills.Bargaining.name()); + + if (bargainSkill != null) + bargain = bargainSkill.getModifiedAmountBeforeMods(); + + if (bargain > 100) + bargain = 100; + + bargain *= .01f; + + return bargain; + } + + public static boolean isDirtyLoad(PlayerCharacter playerCharacter) { + boolean dirtyValue; + playerCharacter.dirtyLock.readLock().lock(); + dirtyValue = playerCharacter.dirtyLoad; + playerCharacter.dirtyLock.readLock().unlock(); + return dirtyValue; + } + + public static void setDirtyLoad(PlayerCharacter playerCharacter, boolean dirtyLoad) { + playerCharacter.dirtyLock.writeLock().lock(); + playerCharacter.dirtyLoad = dirtyLoad; + playerCharacter.dirtyLock.writeLock().unlock(); + } + + public static void ResetLevel(PlayerCharacter playerCharacter, short targetLevel) { + + if (targetLevel > 13) { + ChatManager.chatSystemError(playerCharacter, "Please choose a level between 1 and 13."); + return; + } + playerCharacter.promotionClass = null; + if (targetLevel > 10) { + playerCharacter.level = 10; + playerCharacter.exp = Experience.getBaseExperience(11); + int maxEXP = Experience.getBaseExperience(targetLevel); //target level exp; + playerCharacter.setOverFlowEXP(maxEXP - playerCharacter.exp); + } else { + playerCharacter.level = targetLevel; + playerCharacter.exp = Experience.getBaseExperience(playerCharacter.level); + playerCharacter.setOverFlowEXP(0); + } + + + for (CharacterSkill skill : playerCharacter.getSkills().values()) { + skill.reset(playerCharacter, true); + } + + for (CharacterPower power : playerCharacter.getPowers().values()) { + power.reset(playerCharacter); + } + + playerCharacter.recalculatePlayerStats(playerCharacter.initialized); + playerCharacter.recalculate(); + + ChatManager.chatSystemInfo(playerCharacter, "Character reset to " + targetLevel + ". All training points have been refunded. Relog to update changes on client."); + + } + + public static void updateSkillsAndPowersToDatabase(PlayerCharacter playerCharacter) { + if (playerCharacter.skills != null) + for (CharacterSkill skill : playerCharacter.skills.values()) { + DbManager.CharacterSkillQueries.UPDATE_TRAINS(skill); + if (playerCharacter.powers != null) + for (CharacterPower power : playerCharacter.powers.values()) { + DbManager.CharacterPowerQueries.UPDATE_TRAINS(power); + } + } + } + + public static boolean commandSiegeMinion(PlayerCharacter playerCharacter, Mob toCommand) { + if (!toCommand.isSiege()) + return false; + if (toCommand.isPet() || !toCommand.isAlive()) + return false; + + if (toCommand.getGuild().getNation() != playerCharacter.getGuild().getNation()) + return false; + + if (playerCharacter.getPet() != null) { + Mob currentPet = playerCharacter.getPet(); + if (!currentPet.isSiege()) { + + currentPet.setCombatTarget(null); + + if (currentPet.getParentZone() != null) + + currentPet.getParentZone().zoneMobSet.remove(currentPet); + + try { + currentPet.clearEffects(); + } catch (Exception e) { + Logger.error(e.getMessage()); + } + currentPet.playerAgroMap.clear(); + WorldGrid.RemoveWorldObject(currentPet); + DbManager.removeFromCache(currentPet); + + } else if (currentPet.isSiege()) { + currentPet.agentType = Enum.AIAgentType.MOBILE; + currentPet.setOwner(null); + currentPet.setCombatTarget(null); + if (currentPet.isAlive()) + WorldGrid.updateObject(currentPet); + } + } + + toCommand.setPet(playerCharacter, false); + playerCharacter.setPet(toCommand); + toCommand.setCombatTarget(null); + PetMsg petMsg = new PetMsg(6, toCommand); + Dispatch dispatch = Dispatch.borrow(playerCharacter, petMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); + + if (toCommand.isAlive()) + WorldGrid.updateObject(toCommand); + return true; + } + + public static boolean isFlying(PlayerCharacter playerCharacter) { + + return playerCharacter.getAltitude() > 0; + + } + + public static boolean isSwimming(PlayerCharacter playerCharacter) { + + // If char is flying they aren't quite swimming + try { + if (isFlying(playerCharacter)) + return false; + + Zone zone = ZoneManager.findSmallestZone(playerCharacter.getLoc()); + + if (zone.getSeaLevel() != 0) { + + float localAltitude = playerCharacter.getLoc().y + playerCharacter.centerHeight; + if (localAltitude < zone.getSeaLevel()) + return true; + } else { + if (playerCharacter.getLoc().y + playerCharacter.centerHeight < 0) + return true; + } + } catch (Exception e) { + Logger.info(playerCharacter.getName() + e); + } + + return false; + } + + public static boolean hasBoon(PlayerCharacter playerCharacter) { + for (Effect eff : playerCharacter.getEffects().values()) { + if (eff.getPowerToken() == -587743986 || eff.getPowerToken() == -1660519801 || eff.getPowerToken() == -1854683250) + return true; + } + return false; + } + + public static void updateBlessingMessage(PlayerCharacter playerCharacter) { + + if (playerCharacter.getTimeStamp("RealmClaim") > System.currentTimeMillis()) + return; + + int count = 0; + + for (Effect eff : playerCharacter.getEffects().values()) { + if (eff.getPowerToken() == -587743986 || eff.getPowerToken() == -1660519801 || eff.getPowerToken() == -1854683250) + count++; + } + + if (count > 0) { + playerCharacter.getTimestamps().put("RealmClaim", DateTime.now().plusMinutes(3).getMillis()); + for (PlayerCharacter toSend : SessionManager.getAllActivePlayerCharacters()) { + ChatManager.chatSystemInfo(toSend, playerCharacter.getCombinedName() + " is seeking to claim a realm and already has " + count + " blessngs!"); + } + } + } + + public static void respawn(PlayerCharacter playerCharacter, boolean setAlive, boolean enterWorld, boolean makeCorpse) { + + // Recalculate everything + if(playerCharacter.getTimestamps().containsKey("DeathTime")) + playerCharacter.getTimestamps().remove("DeathTime"); + + playerCharacter.recalculatePlayerStats(true); + playerCharacter.setCombat(false); + + // Set Health to 1/4 max + + + Corpse corpse = null; + + if (makeCorpse) { + try { + corpse = Corpse.makeCorpse(playerCharacter, enterWorld); + } catch (Exception e) { + Logger.error(e); + } + //if we're not making corpse, just purge inventory. used for characters dead while logged out. + } + + if (!setAlive) { + if (corpse == null && makeCorpse) { + Logger.error("Corpse not created."); + } else { + if (makeCorpse && corpse != null) { + InterestManager.forceLoad(corpse); + } + } + return; + } + + playerCharacter.setHealth((float) (playerCharacter.healthMax * .25)); + playerCharacter.isAlive.set(true); + + + // Put player in safe mode + // Teleport the player to his bind loc + // or to a ruin as apporpriate. + + Building bindBuilding = BuildingManager.getBuildingFromCache(playerCharacter.getBindBuildingID()); + + if (enterWorld) { + playerCharacter.stopMovement(playerCharacter.getBindLoc()); + } else if (bindBuilding != null) { + if (bindBuilding.getParentZone().equals(ZoneManager.findSmallestZone(playerCharacter.getLoc()))) + teleport(playerCharacter, Enum.Ruins.getRandomRuin().getLocation()); + else + teleport(playerCharacter, playerCharacter.getBindLoc()); + } else // no bind building found for player, teleport to ruins. + teleport(playerCharacter, Enum.Ruins.getRandomRuin().getLocation()); + + playerCharacter.lastUpdateTime = System.currentTimeMillis(); + playerCharacter.lastStamUpdateTime = System.currentTimeMillis(); + + playerCharacter.update(false); + + PowersManager.applyPower(playerCharacter, playerCharacter, Vector3fImmutable.ZERO, -1661758934, 40, false); + + if (corpse == null && makeCorpse) { + Logger.error("Corpse not created."); + } else { + if (makeCorpse && corpse != null) { + InterestManager.forceLoad(corpse); + } + } + } + + public static Effect addCityEffect(PlayerCharacter playerCharacter, String name, EffectsBase eb, int trains, int duration, boolean onEnter, City city) { + JobContainer jc = null; + if (onEnter) { + NoTimeJob ntj = new NoTimeJob(playerCharacter, name, eb, trains); //infinite timer + ntj.setEffectSourceType(city.getObjectType().ordinal()); + ntj.setEffectSourceID(city.getObjectUUID()); + jc = new JobContainer(ntj); + } else { + FinishSpireEffectJob fsej = new FinishSpireEffectJob(playerCharacter, name, eb, trains); + fsej.setEffectSourceType(city.getObjectType().ordinal()); + fsej.setEffectSourceID(city.getObjectUUID()); + jc = JobScheduler.getInstance().scheduleJob(fsej, duration); + } + + if (playerCharacter.effects.get(name) != null) + playerCharacter.effects.get(name).cancelJob(); + + Effect eff = new Effect(jc, eb, trains); + playerCharacter.effects.put(name, eff); + playerCharacter.applyAllBonuses(); + eff.sendSpireEffect(playerCharacter.getClientConnection(), onEnter); + return eff; + } + + public static void addStr(PlayerCharacter playerCharacter, int amount) { + + boolean worked = false; + short newStr = (short) 0; + while (!worked) { + + if ((playerCharacter.getUnusedStatPoints() - playerCharacter.trainedStatPoints) <= 0) + return; + + newStr = (short) (playerCharacter.statStrBase + amount); + short mod = (short) playerCharacter.strMod.get(); + short newStrMod = (short) (mod + amount); + + if (newStr > playerCharacter.statStrMax) { + newStrMod += (playerCharacter.statStrMax - newStr); + newStr = playerCharacter.statStrMax; + } + worked = playerCharacter.strMod.compareAndSet(mod, newStrMod); + } + playerCharacter.trainedStatPoints++; + playerCharacter.statStrBase = newStr; + playerCharacter.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); + playerCharacter.applyBonuses(); + playerCharacter.calculateSkills(); + } + + public static void addDex(PlayerCharacter playerCharacter, int amount) { + + boolean worked = false; + short newDex = (short) 0; + + while (!worked) { + + if ((playerCharacter.getUnusedStatPoints() - playerCharacter.trainedStatPoints) <= 0) + return; + + newDex = (short) (playerCharacter.statDexBase + amount); + short mod = (short) playerCharacter.dexMod.get(); + short newDexMod = (short) (mod + amount); + + if (newDex > playerCharacter.statDexMax) { + newDexMod += (playerCharacter.statDexMax - newDex); + newDex = playerCharacter.statDexMax; + } + + worked = playerCharacter.dexMod.compareAndSet(mod, newDexMod); + } + playerCharacter.trainedStatPoints++; + playerCharacter.statDexBase = newDex; + playerCharacter.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); + playerCharacter.applyBonuses(); + playerCharacter.calculateSkills(); + } + + public static void addCon(PlayerCharacter playerCharacter, int amount) { + boolean worked = false; + short newCon = (short) 0; + while (!worked) { + + if ((playerCharacter.getUnusedStatPoints() - playerCharacter.trainedStatPoints) <= 0) + return; + + newCon = (short) (playerCharacter.statConBase + amount); + short mod = (short) playerCharacter.conMod.get(); + short newConMod = (short) (mod + amount); + + if (newCon > playerCharacter.statConMax) { + newConMod += (playerCharacter.statConMax - newCon); + newCon = playerCharacter.statConMax; + } + worked = playerCharacter.conMod.compareAndSet(mod, newConMod); + } + playerCharacter.trainedStatPoints++; + playerCharacter.statConBase = newCon; + playerCharacter.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); + playerCharacter.applyBonuses(); + playerCharacter.calculateSkills(); + } + + public static void addInt(PlayerCharacter playerCharacter, int amount) { + boolean worked = false; + short newInt = (short) 0; + while (!worked) { + + if ((playerCharacter.getUnusedStatPoints() - playerCharacter.trainedStatPoints) <= 0) + return; + + newInt = (short) (playerCharacter.statIntBase + amount); + short mod = (short) playerCharacter.intMod.get(); + short newIntMod = (short) (mod + amount); + + if (newInt > playerCharacter.statIntMax) { + newIntMod += (playerCharacter.statIntMax - newInt); + newInt = playerCharacter.statIntMax; + } + worked = playerCharacter.intMod.compareAndSet(mod, newIntMod); + } + playerCharacter.trainedStatPoints++; + playerCharacter.statIntBase = newInt; + playerCharacter.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); + playerCharacter.applyBonuses(); + playerCharacter.calculateSkills(); + } + + public static void addSpi(PlayerCharacter playerCharacter, int amount) { + boolean worked = false; + short newSpi = (short) 0; + + while (!worked) { + + if ((playerCharacter.getUnusedStatPoints() - playerCharacter.trainedStatPoints) <= 0) + return; + + newSpi = (short) (playerCharacter.statSpiBase + amount); + short mod = (short) playerCharacter.spiMod.get(); + short newSpiMod = (short) (mod + amount); + + if (newSpi > playerCharacter.statSpiMax) { + newSpiMod += (playerCharacter.statSpiMax - newSpi); + newSpi = playerCharacter.statSpiMax; + } + worked = playerCharacter.spiMod.compareAndSet(mod, newSpiMod); + } + playerCharacter.trainedStatPoints++; + playerCharacter.statSpiBase = newSpi; + playerCharacter.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); + playerCharacter.applyBonuses(); + playerCharacter.calculateSkills(); + } + + public static boolean refineStr(PlayerCharacter playerCharacter) { + boolean worked = false; + short newStr = (short) 0; + + while (!worked) { + + newStr = (short) (playerCharacter.statStrBase - 1); + short mod = (short) playerCharacter.strMod.get(); + + if (mod == 0) + return false; + + short newStrMod = (short) (mod - 1); + + if (newStr < playerCharacter.statStrMin) + return false; + + if (!canRefineLower(playerCharacter, MBServerStatics.STAT_STR_ID)) + return false; + + worked = playerCharacter.strMod.compareAndSet(mod, newStrMod); + } + playerCharacter.trainedStatPoints--; + playerCharacter.statStrBase = newStr; + playerCharacter.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); + playerCharacter.applyBonuses(); + playerCharacter.calculateSkills(); + return true; + } + + public static boolean refineDex(PlayerCharacter playerCharacter) { + boolean worked = false; + short newDex = (short) 0; + + while (!worked) { + newDex = (short) (playerCharacter.statDexBase - 1); + short mod = (short) playerCharacter.dexMod.get(); + + if (mod == 0) + return false; + + short newDexMod = (short) (mod - 1); + + if (newDex < playerCharacter.statDexMin) + return false; + + if (!canRefineLower(playerCharacter, MBServerStatics.STAT_DEX_ID)) + return false; + + worked = playerCharacter.dexMod.compareAndSet(mod, newDexMod); + } + playerCharacter.trainedStatPoints--; + playerCharacter.statDexBase = newDex; + playerCharacter.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); + playerCharacter.applyBonuses(); + playerCharacter.calculateSkills(); + return true; + } + + public static boolean refineCon(PlayerCharacter playerCharacter) { + boolean worked = false; + short newCon = (short) 0; + + while (!worked) { + newCon = (short) (playerCharacter.statConBase - 1); + short mod = (short) playerCharacter.conMod.get(); + + if (mod == 0) + return false; + + short newConMod = (short) (mod - 1); + + if (newCon < playerCharacter.statConMin) + return false; + + if (!canRefineLower(playerCharacter, MBServerStatics.STAT_CON_ID)) + return false; + + worked = playerCharacter.conMod.compareAndSet(mod, newConMod); + } + playerCharacter.trainedStatPoints--; + playerCharacter.statConBase = newCon; + playerCharacter.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); + playerCharacter.applyBonuses(); + playerCharacter.calculateSkills(); + return true; + } + + public static boolean refineInt(PlayerCharacter playerCharacter, RefineMsg msg) { + boolean worked = false; + short newInt = (short) 0; + + while (!worked) { + newInt = (short) (playerCharacter.statIntBase - 1); + short mod = (short) playerCharacter.intMod.get(); + + if (mod == 0) + return false; + short newIntMod = (short) (mod + - 1); + + if (newInt < playerCharacter.statIntMin) + return false; + + if (!canRefineLower(playerCharacter, MBServerStatics.STAT_INT_ID)) + return false; + + worked = playerCharacter.intMod.compareAndSet(mod, newIntMod); + } + playerCharacter.trainedStatPoints--; + playerCharacter.statIntBase = newInt; + playerCharacter.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); + + verifySkillMax(playerCharacter, msg); + + playerCharacter.applyBonuses(); + playerCharacter.calculateSkills(); + return true; + } + + public static boolean refineSpi(PlayerCharacter playerCharacter) { + boolean worked = false; + short newSpi = (short) 0; + while (!worked) { + newSpi = (short) (playerCharacter.statSpiBase - 1); + short mod = (short) playerCharacter.spiMod.get(); + if (mod == 0) + return false; + short newSpiMod = (short) (mod - 1); + if (newSpi < playerCharacter.statSpiMin) + return false; + if (!canRefineLower(playerCharacter, MBServerStatics.STAT_SPI_ID)) + return false; + worked = playerCharacter.spiMod.compareAndSet(mod, newSpiMod); + } + playerCharacter.trainedStatPoints--; + playerCharacter.statSpiBase = newSpi; + playerCharacter.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); + playerCharacter.applyBonuses(); + playerCharacter.calculateSkills(); + return true; + } + + //this verifies stat doesn't fall too low to keep runes applied while refining + private static boolean canRefineLower(PlayerCharacter playerCharacter, int stat) { + for (CharacterRune cr : playerCharacter.getRunes()) { + if (cr != null) { + RuneBase rb = cr.getRuneBase(); + if (rb != null) { + ArrayList attrs = rb.getAttrs(); + + if (attrs != null) + for (RuneBaseAttribute rba : attrs) { + int attrID = rba.getAttributeID(); + int mod = rba.getModValue(); + if (stat == MBServerStatics.STAT_STR_ID) { + if (attrID == MBServerStatics.RUNE_STR_MIN_NEEDED_ATTRIBUTE_ID && ((int) playerCharacter.statStrBase <= mod)) + return false; + } else if (stat == MBServerStatics.STAT_DEX_ID) { + if (attrID == MBServerStatics.RUNE_DEX_MIN_NEEDED_ATTRIBUTE_ID && ((int) playerCharacter.statDexBase <= mod)) + return false; + } else if (stat == MBServerStatics.STAT_CON_ID) { + if (attrID == MBServerStatics.RUNE_CON_MIN_NEEDED_ATTRIBUTE_ID && ((int) playerCharacter.statConBase <= mod)) + return false; + } else if (stat == MBServerStatics.STAT_INT_ID) { + if (attrID == MBServerStatics.RUNE_INT_MIN_NEEDED_ATTRIBUTE_ID && ((int) playerCharacter.statIntBase <= mod)) + return false; + } else if (stat == MBServerStatics.STAT_SPI_ID) + if (attrID == MBServerStatics.RUNE_SPI_MIN_NEEDED_ATTRIBUTE_ID && ((int) playerCharacter.statSpiBase <= mod)) + return false; + } + } + } + } + + return true; + } + + //checked on refining int to see if skills need refined also. + private static void verifySkillMax(PlayerCharacter playerCharacter, RefineMsg msg) { + + ConcurrentHashMap skills = playerCharacter.getSkills(); + + //make sure no skills are over the max number of trains + int maxTrains = CharacterSkill.getMaxTrains((int) playerCharacter.statIntBase); + + RefineMsg rm = new RefineMsg(msg.getNpcType(), msg.getNpcID(), 0, 0); + + for (CharacterSkill skill : skills.values()) { + + while (skill.getNumTrains() > maxTrains) { + boolean worked = skill.refine(playerCharacter, false); //refine skill, do not recalculate everything + if (worked) { + rm.setToken(skill.getToken()); + + Dispatch dispatch = Dispatch.borrow(playerCharacter, rm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + } else { + Logger.error("Failed to force refine of skill " + skill.getObjectUUID() + " by character " + playerCharacter.getObjectUUID()); + break; + } + } + } + } + + public static int getClassToken(PlayerCharacter playerCharacter) { + if (playerCharacter.promotionClass != null) + return playerCharacter.promotionClass.getToken(); + else if (playerCharacter.getBaseClass() != null) + return playerCharacter.getBaseClass().getToken(); + return 0; + } + + public static int getRaceToken(PlayerCharacter playerCharacter) { + + if (playerCharacter.getRace() == null) + return 0; + + return playerCharacter.getRace().getToken(); + } + + public static synchronized void grantXP(PlayerCharacter playerCharacter, int xp) { + if(playerCharacter.promotionClass == null && playerCharacter.level == 10){ + playerCharacter.setOverFlowEXP(0); + playerCharacter.update(false); + playerCharacter.incVer(); + playerCharacter.recalculate(); + playerCharacter.calculateMaxHealthManaStamina(); + playerCharacter.setHealth(playerCharacter.healthMax); + playerCharacter.mana.set(playerCharacter.getManaMax()); + playerCharacter.stamina.set(playerCharacter.getStaminaMax()); + //LoadJob.reloadCharacter(this); + DbManager.PlayerCharacterQueries.SET_PROPERTY(playerCharacter, "char_experience", playerCharacter.exp); + // updateDatabase(); + DbManager.AccountQueries.INVALIDATE_LOGIN_CACHE(playerCharacter.getObjectUUID(), "character"); + return; + } + // Stop players from getting experience past the cap + if (playerCharacter.exp + xp >= Experience.getBaseExperience(MBServerStatics.LEVELCAP)) + xp = Experience.getBaseExperience(MBServerStatics.LEVELCAP) - playerCharacter.exp + 1; + + if (xp == 0) + xp = 1; + + boolean isNewLevel = false; + boolean charReloadRequired = false; + int remainingXP = xp; + int neededXP = 0; + + // handle players that have not yet promoted. + ClientConnection origin = playerCharacter.getClientConnection(); + + //not promoted at level 10, start checking for negative EXP + if (playerCharacter.promotionClass == null && playerCharacter.getLevel() == 10) { + + if (playerCharacter.getExp() == Experience.getBaseExperience(11)) { + if (playerCharacter.overFlowEXP == 110000) + return; + + if (playerCharacter.overFlowEXP + xp > 110000) { + remainingXP = 110000 - playerCharacter.overFlowEXP; + playerCharacter.overFlowEXP = 110000; + + + } else { + playerCharacter.overFlowEXP += remainingXP; + } + + GrantExperienceMsg gem = new GrantExperienceMsg(playerCharacter, remainingXP); + Dispatch dispatch = Dispatch.borrow(playerCharacter, gem); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + playerCharacter.addDatabaseJob("EXP", MBServerStatics.FIVE_MINUTES); + return; + //didnt reach level 11 EXP to start overflow, add exp normally till we get here; + } else { + + //Player exp begins negative exp, add remaing exp after level 11 to overflow + if (playerCharacter.getExp() + remainingXP >= Experience.getBaseExperience(11)) { + + playerCharacter.overFlowEXP = remainingXP - (Experience.getBaseExperience(11) - playerCharacter.getExp()); + playerCharacter.exp = Experience.getBaseExperience(11); + + GrantExperienceMsg grantExperienceMsg = new GrantExperienceMsg(playerCharacter, remainingXP); + Dispatch dispatch = Dispatch.borrow(playerCharacter, grantExperienceMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + playerCharacter.addDatabaseJob("EXP", MBServerStatics.FIVE_MINUTES); + return; + + //didnt reach negative exp yet, just do normal exp gain. + } else { + playerCharacter.exp += remainingXP; + GrantExperienceMsg grantExperienceMsg = new GrantExperienceMsg(playerCharacter, remainingXP); + remainingXP = 0; + Dispatch dispatch = Dispatch.borrow(playerCharacter, grantExperienceMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + playerCharacter.addDatabaseJob("EXP", MBServerStatics.FIVE_MINUTES); + return; + } + } + } + + if (playerCharacter.overFlowEXP > 0) { + + int nextLevel; + + if (playerCharacter.level == 10) + nextLevel = 12; + else + nextLevel = playerCharacter.level + 2; + + int nextLevelEXP = Experience.getBaseExperience(nextLevel); + + // if overflow > 0, u have level 11 experience + overflow, but level is still 10 due to just promoting. + //Use level + 2 experience for next level. + playerCharacter.overFlowEXP += 1; + + if (playerCharacter.getExp() + playerCharacter.overFlowEXP >= nextLevelEXP) { + + int expToNextLevel = nextLevelEXP - playerCharacter.getExp(); + playerCharacter.overFlowEXP -= expToNextLevel; + playerCharacter.exp += expToNextLevel; + playerCharacter.level++; + charReloadRequired = true; + + GrantExperienceMsg grantExperienceMsg = new GrantExperienceMsg(playerCharacter, 1); + Dispatch dispatch = Dispatch.borrow(playerCharacter, grantExperienceMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + SetObjectValueMsg upm = new SetObjectValueMsg(playerCharacter, 9); + DispatchMessage.dispatchMsgToInterestArea(playerCharacter, upm, Enum.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); + checkGuildStatus(playerCharacter); + playerCharacter.addDatabaseJob("EXP", MBServerStatics.FIVE_MINUTES); + // double overflow exp used up, remaining overflow will just add to level + 1. + } else if (playerCharacter.getExp() + playerCharacter.overFlowEXP >= Experience.getBaseExperience(playerCharacter.level + 1)) { + int nextExperience = Experience.getBaseExperience(playerCharacter.level + 1) + playerCharacter.overFlowEXP; + playerCharacter.exp = nextExperience; + playerCharacter.level++; + charReloadRequired = true; + playerCharacter.overFlowEXP = 0; + GrantExperienceMsg grantExperienceMsg = new GrantExperienceMsg(playerCharacter, 1); + Dispatch dispatch = Dispatch.borrow(playerCharacter, grantExperienceMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + SetObjectValueMsg upm = new SetObjectValueMsg(playerCharacter, 9); + DispatchMessage.dispatchMsgToInterestArea(playerCharacter, upm, Enum.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); + checkGuildStatus(playerCharacter); + playerCharacter.addDatabaseJob("EXP", MBServerStatics.FIVE_MINUTES); + } + + } else { + // Hand out each Level one at a time. + isNewLevel = Experience.getLevel(playerCharacter.exp + remainingXP) > playerCharacter.getLevel(); + + if (isNewLevel) { + neededXP = Experience.getBaseExperience(playerCharacter.getLevel() + 1) - playerCharacter.exp; + + charReloadRequired = true; + playerCharacter.exp += neededXP; + playerCharacter.level++; + + GrantExperienceMsg grantExperienceMsg = new GrantExperienceMsg(playerCharacter, neededXP); + Dispatch dispatch = Dispatch.borrow(playerCharacter, grantExperienceMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + remainingXP -= neededXP; + + //Send newLevel. + SetObjectValueMsg upm = new SetObjectValueMsg(playerCharacter, 9); + DispatchMessage.dispatchMsgToInterestArea(playerCharacter, upm, Enum.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); + checkGuildStatus(playerCharacter); + } else { + + playerCharacter.exp += remainingXP; + GrantExperienceMsg grantExperienceMsg = new GrantExperienceMsg(playerCharacter, remainingXP); + remainingXP = 0; + Dispatch dispatch = Dispatch.borrow(playerCharacter, grantExperienceMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + playerCharacter.addDatabaseJob("EXP", MBServerStatics.FIVE_MINUTES); + } + } + + if (charReloadRequired) { + playerCharacter.update(false); + playerCharacter.incVer(); + playerCharacter.recalculate(); + playerCharacter.calculateMaxHealthManaStamina(); + playerCharacter.setHealth(playerCharacter.healthMax); + playerCharacter.mana.set(playerCharacter.getManaMax()); + playerCharacter.stamina.set(playerCharacter.getStaminaMax()); + //LoadJob.reloadCharacter(this); + DbManager.PlayerCharacterQueries.SET_PROPERTY(playerCharacter, "char_experience", playerCharacter.exp); + // updateDatabase(); + DbManager.AccountQueries.INVALIDATE_LOGIN_CACHE(playerCharacter.getObjectUUID(), "character"); + } + } + + //This checks if a player meets the requirements to be in current guild. + public static void checkGuildStatus(PlayerCharacter playerCharacter) { + + Guild g = playerCharacter.guild; + + if (g == null || g.isEmptyGuild() || GuildStatusController.isGuildLeader(playerCharacter.getGuildStatus())) + return; + + //check level + int curLevel = (int) playerCharacter.getPCLevel(); + if (curLevel < g.getRepledgeMin() || curLevel >= g.getRepledgeKick()) { + //TODO kick from guild + g.removePlayer(playerCharacter, Enum.GuildHistoryType.LEAVE); + ChatManager.chatGuildInfo(playerCharacter, "You no longer meet the level requirements for the guild."); + } + } + + public static void calculateSpeedMod(PlayerCharacter playerCharacter) { + // get base race speed modifer + + + //this is retarded. *** Refactor + // if (this.race != null) { + // int ID = this.race.getObjectUUID(); + // if (ID == 2004 || ID == 2005) + // this.raceRunMod = 1.21f; // centaur run bonus 22% + //// else if (ID == 2017) + //// this.raceRunMod = 1.14f; // mino run bonus 15% + // else + // this.raceRunMod = 1; + // } else + // this.raceRunMod = 1; + + + float bonus = 1f; + + // // TODO: hardcoded, as didnt have time to introduce DB column to base object + // if (baseClass.getName().equals("Fighter") || baseClass.getName().equals("Rogue")) + // bonus += .05f; + + // get running skill + if (playerCharacter.skills != null) { + CharacterSkill running = playerCharacter.skills.get("Running"); + if (running != null) { + + float runningBonus = (float) (Math.log(Math.round(running.getModifiedAmount()) * .01f) / Math.log(2) * .50f); + runningBonus = (float) (Math.pow(2, runningBonus) - 1); + runningBonus += 1; + runningBonus *= .25f; + bonus += runningBonus; + + } + } + + if (playerCharacter.bonuses != null) + // get rune and effect bonuses + bonus += playerCharacter.bonuses.getFloatPercentNullZero(Enum.ModType.Speed, Enum.SourceType.None); + + // TODO get equip bonus + playerCharacter.update(false); + playerCharacter.speedMod = bonus; + } +} diff --git a/src/engine/gameManager/PowersManager.java b/src/engine/gameManager/PowersManager.java index 744586d3..9d6a26be 100644 --- a/src/engine/gameManager/PowersManager.java +++ b/src/engine/gameManager/PowersManager.java @@ -165,7 +165,7 @@ public enum PowersManager { PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); - if(!pc.isFlying()) //cant be sitting if flying + if(!PlayerManager.isFlying(pc)) //cant be sitting if flying CombatManager.toggleSit(false,origin); if(pc.isMoving()) @@ -294,7 +294,7 @@ public enum PowersManager { } //check for movement buffs while flying - if(playerCharacter.isFlying()) { + if(PlayerManager.isFlying(playerCharacter)) { switch(pb.token){ case 429005674: case 429505739: @@ -1363,7 +1363,7 @@ public enum PowersManager { if (pc == null) return; - PlayerCharacter source = PlayerCharacter.getFromCache(msg.getSourceID()); + PlayerCharacter source = PlayerManager.getFromCache(msg.getSourceID()); if (source == null) return; diff --git a/src/engine/gameManager/TradeManager.java b/src/engine/gameManager/TradeManager.java index 15d6e2df..a576f065 100644 --- a/src/engine/gameManager/TradeManager.java +++ b/src/engine/gameManager/TradeManager.java @@ -151,7 +151,7 @@ public enum TradeManager { } public static void invalidTradeRequest(InvalidTradeRequestMsg msg) { - PlayerCharacter requester = PlayerCharacter.getFromCache(msg.getRequesterID()); + PlayerCharacter requester = PlayerManager.getFromCache(msg.getRequesterID()); Dispatch dispatch; dispatch = Dispatch.borrow(requester, msg); diff --git a/src/engine/jobs/DatabaseUpdateJob.java b/src/engine/jobs/DatabaseUpdateJob.java index fa45cf44..dff77de2 100644 --- a/src/engine/jobs/DatabaseUpdateJob.java +++ b/src/engine/jobs/DatabaseUpdateJob.java @@ -11,6 +11,7 @@ package engine.jobs; import engine.Enum.GameObjectType; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.job.AbstractScheduleJob; import engine.objects.AbstractGameObject; import engine.objects.Building; @@ -39,7 +40,7 @@ public class DatabaseUpdateJob extends AbstractScheduleJob { switch (this.type) { case "Skills": - pc.updateSkillsAndPowersToDatabase(); + PlayerManager.updateSkillsAndPowersToDatabase(pc); break; case "Stats": DbManager.PlayerCharacterQueries.UPDATE_CHARACTER_STATS(pc); diff --git a/src/engine/jobs/FinishSummonsJob.java b/src/engine/jobs/FinishSummonsJob.java index 77fb3de3..f0ee492b 100644 --- a/src/engine/jobs/FinishSummonsJob.java +++ b/src/engine/jobs/FinishSummonsJob.java @@ -11,7 +11,7 @@ package engine.jobs; import engine.Enum.ModType; import engine.Enum.SourceType; -import engine.gameManager.PowersManager; +import engine.gameManager.PlayerManager; import engine.job.AbstractScheduleJob; import engine.job.JobContainer; import engine.net.client.msg.ErrorPopupMsg; @@ -64,7 +64,7 @@ public class FinishSummonsJob extends AbstractScheduleJob { if (this.source.region != null) this.target.setRegion(this.source.region); //teleport target to source - target.teleport(source.getLoc()); + PlayerManager.teleport(target, source.getLoc()); } @Override diff --git a/src/engine/jobs/StuckJob.java b/src/engine/jobs/StuckJob.java index 79d5541c..d18b09f5 100644 --- a/src/engine/jobs/StuckJob.java +++ b/src/engine/jobs/StuckJob.java @@ -9,6 +9,7 @@ package engine.jobs; import engine.InterestManagement.WorldGrid; +import engine.gameManager.PlayerManager; import engine.job.AbstractScheduleJob; import engine.math.Bounds; import engine.math.Vector3fImmutable; @@ -69,7 +70,7 @@ public class StuckJob extends AbstractScheduleJob { return; } - player.teleport(stuckLoc); + PlayerManager.teleport(player, stuckLoc); } diff --git a/src/engine/jobs/TeleportJob.java b/src/engine/jobs/TeleportJob.java index 0bb94f8e..b637dce8 100644 --- a/src/engine/jobs/TeleportJob.java +++ b/src/engine/jobs/TeleportJob.java @@ -9,6 +9,7 @@ package engine.jobs; +import engine.gameManager.PlayerManager; import engine.job.AbstractScheduleJob; import engine.math.Vector3fImmutable; import engine.net.client.ClientConnection; @@ -52,7 +53,7 @@ public class TeleportJob extends AbstractScheduleJob { return; } - pc.teleport(loc); + PlayerManager.teleport(pc, loc); if (this.setSafeMode) pc.setSafeMode(); diff --git a/src/engine/mobileAI/MobAI.java b/src/engine/mobileAI/MobAI.java index cabe0d9d..11d45ac4 100644 --- a/src/engine/mobileAI/MobAI.java +++ b/src/engine/mobileAI/MobAI.java @@ -9,7 +9,6 @@ package engine.mobileAI; import engine.Enum; -import engine.Enum.DispatchChannel; import engine.InterestManagement.WorldGrid; import engine.gameManager.*; import engine.math.Vector3f; @@ -17,9 +16,7 @@ import engine.math.Vector3fImmutable; import engine.mobileAI.Threads.MobAIThread; import engine.mobileAI.utilities.CombatUtilities; import engine.mobileAI.utilities.MovementUtilities; -import engine.net.DispatchMessage; import engine.net.client.msg.PerformActionMsg; -import engine.net.client.msg.PowerProjectileMsg; import engine.objects.*; import engine.powers.ActionsBase; import engine.powers.PowersBase; @@ -85,7 +82,7 @@ public class MobAI { if(mob.StrongholdGuardian || mob.StrongholdEpic){ // attempt to ground all players in attack range for(int i : mob.playerAgroMap.keySet()){ - PlayerCharacter tar = PlayerCharacter.getFromCache(i); + PlayerCharacter tar = PlayerManager.getFromCache(i); if(tar != null && tar.loc.distanceSquared(mob.loc) < 80){ PowersManager.applyPower(mob,tar,tar.loc, 111111,40,false); } @@ -727,7 +724,7 @@ public class MobAI { for (Entry playerEntry : loadedPlayers.entrySet()) { int playerID = (int) playerEntry.getKey(); - PlayerCharacter loadedPlayer = PlayerCharacter.getFromCache(playerID); + PlayerCharacter loadedPlayer = PlayerManager.getFromCache(playerID); //Player is null, let's remove them from the list. @@ -980,7 +977,7 @@ public class MobAI { mob.setCombatTarget(null); for (Entry playerEntry : mob.playerAgroMap.entrySet()) - PlayerCharacter.getFromCache((int) playerEntry.getKey()).setHateValue(0); + PlayerManager.getFromCache((int) playerEntry.getKey()).setHateValue(0); mob.setCombatTarget(null); } } catch (Exception e) { @@ -1218,7 +1215,7 @@ public class MobAI { for (Entry playerEntry : loadedPlayers.entrySet()) { int playerID = (int) playerEntry.getKey(); - PlayerCharacter loadedPlayer = PlayerCharacter.getFromCache(playerID); + PlayerCharacter loadedPlayer = PlayerManager.getFromCache(playerID); //Player is null, let's remove them from the list. @@ -1379,7 +1376,7 @@ public class MobAI { for (Entry playerEntry : mob.playerAgroMap.entrySet()) { - PlayerCharacter potentialTarget = PlayerCharacter.getFromCache((int) playerEntry.getKey()); + PlayerCharacter potentialTarget = PlayerManager.getFromCache((int) playerEntry.getKey()); if (potentialTarget.equals(mob.getCombatTarget())) continue; diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 1424c2be..0d5df544 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -603,19 +603,19 @@ public class ClientMessagePump implements NetMsgHandler { switch (type) { case MBServerStatics.STAT_STR_ID: - pc.addStr(msg.getAmount()); + PlayerManager.addStr(pc, msg.getAmount()); break; case MBServerStatics.STAT_DEX_ID: - pc.addDex(msg.getAmount()); + PlayerManager.addDex(pc, msg.getAmount()); break; case MBServerStatics.STAT_CON_ID: - pc.addCon(msg.getAmount()); + PlayerManager.addCon(pc, msg.getAmount()); break; case MBServerStatics.STAT_INT_ID: - pc.addInt(msg.getAmount()); + PlayerManager.addInt(pc, msg.getAmount()); break; case MBServerStatics.STAT_SPI_ID: - pc.addSpi(msg.getAmount()); + PlayerManager.addSpi(pc, msg.getAmount()); break; } } @@ -641,7 +641,7 @@ public class ClientMessagePump implements NetMsgHandler { // ResetAfterDeath player sourcePlayer.respawnLock.writeLock().lock(); try { - sourcePlayer.respawn(true, false, true); + PlayerManager.respawn(sourcePlayer, true, false, true); } catch (Exception e) { Logger.error(e); @@ -705,7 +705,7 @@ public class ClientMessagePump implements NetMsgHandler { switch (targetType) { case PlayerCharacter: - characterTarget = PlayerCharacter.getFromCache(msg.getTargetID()); + characterTarget = PlayerManager.getFromCache(msg.getTargetID()); if (characterTarget == null) return; if (characterTarget.isAlive()) @@ -809,7 +809,7 @@ public class ClientMessagePump implements NetMsgHandler { if (targetType == GameObjectType.PlayerCharacter.ordinal() || targetType == GameObjectType.Mob.ordinal()) { if (targetType == GameObjectType.PlayerCharacter.ordinal()) { - tar = PlayerCharacter.getFromCache(targetID); + tar = PlayerManager.getFromCache(targetID); if (tar == null) return; @@ -1013,7 +1013,7 @@ public class ClientMessagePump implements NetMsgHandler { AbstractCharacter tar = null; if (targetType == GameObjectType.PlayerCharacter.ordinal()) - tar = PlayerCharacter.getFromCache(msg.getTargetID()); + tar = PlayerManager.getFromCache(msg.getTargetID()); else if (targetType == GameObjectType.NPC.ordinal()) tar = NPC.getFromCache(msg.getTargetID()); else if (targetType == GameObjectType.Mob.ordinal()) @@ -1166,7 +1166,7 @@ public class ClientMessagePump implements NetMsgHandler { if (con == null) return; - float bargain = sourcePlayer.getBargain(); + float bargain = PlayerManager.getBargain(sourcePlayer); float profit = npc.getBuyPercent(sourcePlayer) + bargain; @@ -1271,7 +1271,7 @@ public class ClientMessagePump implements NetMsgHandler { float durabilityMax = sell.getDurabilityMax(); float damagedModifier = durabilityCurrent / durabilityMax; cost *= damagedModifier; - float bargain = player.getBargain(); + float bargain = PlayerManager.getBargain(player); float profit = npc.getBuyPercent(player) + bargain; @@ -1422,7 +1422,7 @@ public class ClientMessagePump implements NetMsgHandler { return; } int cost = me.getMagicValue(); - float bargain = sourcePlayer.getBargain(); + float bargain = PlayerManager.getBargain(sourcePlayer); switch(npc.getContractID()){ case 1201: cost = ItemBase.getDiscPrice(ib.getUUID()); @@ -1503,7 +1503,7 @@ public class ClientMessagePump implements NetMsgHandler { int cost = buy.getBaseValue(); if (buy.isID() || buy.isCustomValue()) cost = buy.getMagicValue(); - float bargain = sourcePlayer.getBargain(); + float bargain = PlayerManager.getBargain(sourcePlayer); float profit = npc.getSellPercent(sourcePlayer) - bargain; if (profit < 1) profit = 1; @@ -1821,7 +1821,7 @@ public class ClientMessagePump implements NetMsgHandler { long type = player.getTimeStamp("LastRecallType"); if (type == 1) { //recall to bind - player.teleport(player.getBindLoc()); + PlayerManager.teleport(player, player.getBindLoc()); player.setSafeMode(); } else { //recall to rg float dist = 9999999999f; @@ -1842,7 +1842,7 @@ public class ClientMessagePump implements NetMsgHandler { //nearest runegate found. teleport characterTarget if (rg != null) { - player.teleport(rg.getLoc()); + PlayerManager.teleport(player, rg.getLoc()); player.setSafeMode(); } } diff --git a/src/engine/net/client/handlers/AcceptInviteToGuildHandler.java b/src/engine/net/client/handlers/AcceptInviteToGuildHandler.java index a0269277..71c89d41 100644 --- a/src/engine/net/client/handlers/AcceptInviteToGuildHandler.java +++ b/src/engine/net/client/handlers/AcceptInviteToGuildHandler.java @@ -13,10 +13,7 @@ import engine.Enum; import engine.Enum.GameObjectType; import engine.Enum.GuildHistoryType; import engine.exception.MsgSendException; -import engine.gameManager.ChatManager; -import engine.gameManager.DbManager; -import engine.gameManager.GuildManager; -import engine.gameManager.SessionManager; +import engine.gameManager.*; import engine.net.Dispatch; import engine.net.DispatchMessage; import engine.net.client.ClientConnection; @@ -83,7 +80,7 @@ public class AcceptInviteToGuildHandler extends AbstractClientMsgHandler { player.setGuild(guild); // Cleanup guild stuff - player.resetGuildStatuses(); + PlayerManager.resetGuildStatuses(player); Dispatch dispatch = Dispatch.borrow(player, msg); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); diff --git a/src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java b/src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java index 02b0518c..a8fd8a17 100644 --- a/src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java +++ b/src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java @@ -53,7 +53,7 @@ public class ArcLoginNotifyMsgHandler extends AbstractClientMsgHandler { GroupManager.RefreshOthersGroupList(player); } - player.setEnteredWorld(true); + PlayerManager.setEnteredWorld(player, true); // Set player active player.resetRegenUpdateTime(); player.setActive(true); diff --git a/src/engine/net/client/handlers/BanishUnbanishHandler.java b/src/engine/net/client/handlers/BanishUnbanishHandler.java index e2a88482..421e7b99 100644 --- a/src/engine/net/client/handlers/BanishUnbanishHandler.java +++ b/src/engine/net/client/handlers/BanishUnbanishHandler.java @@ -14,6 +14,7 @@ import engine.Enum.GuildHistoryType; import engine.exception.MsgSendException; import engine.gameManager.ChatManager; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.gameManager.SessionManager; import engine.net.Dispatch; import engine.net.DispatchMessage; @@ -55,7 +56,7 @@ public class BanishUnbanishHandler extends AbstractClientMsgHandler { boolean success = false; Guild guild = source.getGuild(); - PlayerCharacter realizedTarget = PlayerCharacter.getFromCache(target); + PlayerCharacter realizedTarget = PlayerManager.getFromCache(target); if (realizedTarget != null) { // Guild leader can't leave guild. must pass GL or disband @@ -83,7 +84,7 @@ public class BanishUnbanishHandler extends AbstractClientMsgHandler { } } else { if (guild.getGuildLeaderUUID() != target) { - PlayerCharacter toBanish = PlayerCharacter.getPlayerCharacter(target); + PlayerCharacter toBanish = PlayerManager.getPlayerCharacter(target); if (toBanish == null) return true; //already added previously. @@ -110,7 +111,7 @@ public class BanishUnbanishHandler extends AbstractClientMsgHandler { //DbManager.GuildQueries.ADD_TO_BANISHED_FROM_GUILDLIST(guild.getobjectUUID(), target); // Send left guild message to rest of guild - String targetName = PlayerCharacter.getFirstName(target); + String targetName = PlayerManager.getFirstName(target); ChatManager.chatGuildInfo(guild, targetName + " has been banished from " + guild.getName() + '.'); GuildListMsg guildListMsg = new GuildListMsg(guild); diff --git a/src/engine/net/client/handlers/ChangeAltitudeHandler.java b/src/engine/net/client/handlers/ChangeAltitudeHandler.java index db4a0e78..2821d7ef 100644 --- a/src/engine/net/client/handlers/ChangeAltitudeHandler.java +++ b/src/engine/net/client/handlers/ChangeAltitudeHandler.java @@ -11,6 +11,7 @@ package engine.net.client.handlers; import engine.Enum.DispatchChannel; import engine.exception.MsgSendException; +import engine.gameManager.PlayerManager; import engine.net.DispatchMessage; import engine.net.client.ClientConnection; import engine.net.client.msg.ChangeAltitudeMsg; @@ -42,7 +43,7 @@ public class ChangeAltitudeHandler extends AbstractClientMsgHandler { if (!AbstractCharacter.CanFly(pc)) return false; - if (pc.isSwimming()) + if (PlayerManager.isSwimming(pc)) return false; if (pc.region != null && !pc.region.isOutside()) return false; diff --git a/src/engine/net/client/handlers/ChangeGuildLeaderHandler.java b/src/engine/net/client/handlers/ChangeGuildLeaderHandler.java index fe21996b..791dfe23 100644 --- a/src/engine/net/client/handlers/ChangeGuildLeaderHandler.java +++ b/src/engine/net/client/handlers/ChangeGuildLeaderHandler.java @@ -14,6 +14,7 @@ import engine.Enum.GameObjectType; import engine.exception.MsgSendException; import engine.gameManager.ChatManager; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.net.Dispatch; import engine.net.DispatchMessage; import engine.net.client.ClientConnection; @@ -97,9 +98,9 @@ public class ChangeGuildLeaderHandler extends AbstractClientMsgHandler { } - targetPlayer.setGuildLeader(true); - targetPlayer.setInnerCouncil(true); - targetPlayer.setFullMember(true); + PlayerManager.setGuildLeader(targetPlayer, true); + PlayerManager.setInnerCouncil(targetPlayer, true); + PlayerManager.setFullMember(targetPlayer, true); targetPlayer.incVer(); targetName = targetPlayer.getFirstName(); updateTarget = true; @@ -113,9 +114,9 @@ public class ChangeGuildLeaderHandler extends AbstractClientMsgHandler { //updateOldGuildLeader - sourcePlayer.setInnerCouncil(true); - sourcePlayer.setFullMember(true); - sourcePlayer.setGuildLeader(false); + PlayerManager.setInnerCouncil(sourcePlayer, true); + PlayerManager.setFullMember(sourcePlayer, true); + PlayerManager.setGuildLeader(sourcePlayer, false); sourcePlayer.incVer(); GuildInfoMsg guildInfoMsg = new GuildInfoMsg(sourcePlayer, sourcePlayer.getGuild(), 2); diff --git a/src/engine/net/client/handlers/ChangeRankHandler.java b/src/engine/net/client/handlers/ChangeRankHandler.java index 8197fbff..538d329f 100644 --- a/src/engine/net/client/handlers/ChangeRankHandler.java +++ b/src/engine/net/client/handlers/ChangeRankHandler.java @@ -14,6 +14,7 @@ import engine.Enum.GameObjectType; import engine.exception.MsgSendException; import engine.gameManager.ChatManager; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.net.Dispatch; import engine.net.DispatchMessage; import engine.net.client.ClientConnection; @@ -63,14 +64,14 @@ public class ChangeRankHandler extends AbstractClientMsgHandler { Enum.GuildType t = Enum.GuildType.getGuildTypeFromInt(sourcePlayer.getGuild().getCharter()); if (targetPlayer != null) { - targetPlayer.setGuildTitle(msg.getNewRank()); + PlayerManager.setGuildTitle(targetPlayer, msg.getNewRank()); targetName = targetPlayer.getFirstName(); isMale = targetPlayer.getRace().getRaceType().getCharacterSex().equals(Enum.CharacterSex.MALE); } else { DbManager.GuildQueries.UPDATE_GUILD_RANK_OFFLINE(msg.getPlayerUUID(), msg.getNewRank(), sourcePlayer.getGuild().getObjectUUID()); - targetName = PlayerCharacter.getFirstName(msg.getPlayerUUID()); + targetName = PlayerManager.getFirstName(msg.getPlayerUUID()); isMale = true; } @@ -98,7 +99,7 @@ public class ChangeRankHandler extends AbstractClientMsgHandler { taxUpdate = (updateMask & 1) > 0; if (targetName == null && updateMask > 0) - targetName = PlayerCharacter.getFirstName(msg.getPlayerUUID()); + targetName = PlayerManager.getFirstName(msg.getPlayerUUID()); } else { icUpdate = (GuildStatusController.isInnerCouncil(targetPlayer.getGuildStatus()) != (msg.getIc() > 0)) && GuildStatusController.isGuildLeader(sourcePlayer.getGuildStatus()); recruitUpdate = (GuildStatusController.isRecruiter(targetPlayer.getGuildStatus()) != (msg.getRec() > 0)) && GuildStatusController.isGuildLeader(sourcePlayer.getGuildStatus()); @@ -106,16 +107,16 @@ public class ChangeRankHandler extends AbstractClientMsgHandler { //This logic branch only executes if targetPlayer has passed a null check... if (icUpdate) { - targetPlayer.setInnerCouncil(msg.getIc() > 0); - targetPlayer.setFullMember(true); + PlayerManager.setInnerCouncil(targetPlayer, msg.getIc() > 0); + PlayerManager.setFullMember(targetPlayer, true); targetPlayer.incVer(); } if (recruitUpdate) - targetPlayer.setRecruiter(msg.getRec() > 0); + PlayerManager.setRecruiter(targetPlayer, msg.getRec() > 0); if (taxUpdate) - targetPlayer.setTaxCollector(msg.getTax() > 0); + PlayerManager.setTaxCollector(targetPlayer, msg.getTax() > 0); if (targetName == null) targetName = targetPlayer.getFirstName(); diff --git a/src/engine/net/client/handlers/DisbandGuildHandler.java b/src/engine/net/client/handlers/DisbandGuildHandler.java index 15e1fbd8..603dda65 100644 --- a/src/engine/net/client/handlers/DisbandGuildHandler.java +++ b/src/engine/net/client/handlers/DisbandGuildHandler.java @@ -17,6 +17,7 @@ import engine.db.archive.GuildRecord; import engine.exception.MsgSendException; import engine.gameManager.ChatManager; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.gameManager.SessionManager; import engine.net.Dispatch; import engine.net.DispatchMessage; @@ -98,8 +99,8 @@ public class DisbandGuildHandler extends AbstractClientMsgHandler { //Save Guild data - player.setGuildLeader(false); - player.setInnerCouncil(false); + PlayerManager.setGuildLeader(player, false); + PlayerManager.setInnerCouncil(player, false); guild.setGuildLeaderUUID(0); guild.setNation(null); diff --git a/src/engine/net/client/handlers/GuildControlHandler.java b/src/engine/net/client/handlers/GuildControlHandler.java index 1654dbae..13ed5f36 100644 --- a/src/engine/net/client/handlers/GuildControlHandler.java +++ b/src/engine/net/client/handlers/GuildControlHandler.java @@ -11,6 +11,7 @@ package engine.net.client.handlers; import engine.Enum; import engine.exception.MsgSendException; +import engine.gameManager.PlayerManager; import engine.gameManager.SessionManager; import engine.net.Dispatch; import engine.net.DispatchMessage; @@ -60,7 +61,7 @@ public class GuildControlHandler extends AbstractClientMsgHandler { PlayerCharacter player = SessionManager.getPlayerCharacter(origin); //If we don't get a valid PC for whatever reason.. just ignore it. - PlayerCharacter pc = PlayerCharacter.getFromCache(msg.getUnknown03()); + PlayerCharacter pc = PlayerManager.getFromCache(msg.getUnknown03()); if (pc != null) { dispatch = Dispatch.borrow(player, new GuildListMsg(pc)); diff --git a/src/engine/net/client/handlers/GuildCreationFinalizeHandler.java b/src/engine/net/client/handlers/GuildCreationFinalizeHandler.java index aed341f4..aeb0bce4 100644 --- a/src/engine/net/client/handlers/GuildCreationFinalizeHandler.java +++ b/src/engine/net/client/handlers/GuildCreationFinalizeHandler.java @@ -15,10 +15,7 @@ import engine.Enum.GuildHistoryType; import engine.Enum.ItemType; import engine.Enum.OwnerType; import engine.exception.MsgSendException; -import engine.gameManager.ChatManager; -import engine.gameManager.DbManager; -import engine.gameManager.GuildManager; -import engine.gameManager.SessionManager; +import engine.gameManager.*; import engine.net.Dispatch; import engine.net.DispatchMessage; import engine.net.client.ClientConnection; @@ -130,10 +127,10 @@ public class GuildCreationFinalizeHandler extends AbstractClientMsgHandler { GuildManager.joinGuild(player, newGuild, GuildHistoryType.CREATE); newGuild.setGuildLeader(player); - player.setGuildLeader(true); - player.setInnerCouncil(true); - player.setFullMember(true); - player.setGuildTitle(charterType.getNumberOfRanks() - 1); + PlayerManager.setGuildLeader(player, true); + PlayerManager.setInnerCouncil(player, true); + PlayerManager.setFullMember(player, true); + PlayerManager.setGuildTitle(player, charterType.getNumberOfRanks() - 1); player.getCharItemManager().delete(charter); player.getCharItemManager().updateInventory(); player.incVer(); diff --git a/src/engine/net/client/handlers/GuildInfoHandler.java b/src/engine/net/client/handlers/GuildInfoHandler.java index 550cdd0a..647b0e22 100644 --- a/src/engine/net/client/handlers/GuildInfoHandler.java +++ b/src/engine/net/client/handlers/GuildInfoHandler.java @@ -11,6 +11,7 @@ package engine.net.client.handlers; import engine.Enum.GameObjectType; import engine.exception.MsgSendException; +import engine.gameManager.PlayerManager; import engine.gameManager.SessionManager; import engine.net.Dispatch; import engine.net.DispatchMessage; @@ -43,7 +44,7 @@ public class GuildInfoHandler extends AbstractClientMsgHandler { } else if (msg.getMsgType() == 5) { if (msg.getObjectType() == GameObjectType.PlayerCharacter.ordinal()) { - PlayerCharacter pc = PlayerCharacter.getPlayerCharacter(msg.getObjectID()); + PlayerCharacter pc = PlayerManager.getPlayerCharacter(msg.getObjectID()); dispatch = Dispatch.borrow(sourcePlayer, new GuildInfoMsg(pc, pc.getGuild(), 5)); DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); } else { diff --git a/src/engine/net/client/handlers/MerchantMsgHandler.java b/src/engine/net/client/handlers/MerchantMsgHandler.java index 2515646d..f8d56a1c 100644 --- a/src/engine/net/client/handlers/MerchantMsgHandler.java +++ b/src/engine/net/client/handlers/MerchantMsgHandler.java @@ -17,7 +17,6 @@ import engine.powers.PowersBase; import engine.server.MBServerStatics; import java.util.ArrayList; -import java.util.Objects; /* * @Author: @@ -347,7 +346,7 @@ public class MerchantMsgHandler extends AbstractClientMsgHandler { TeleportJob tj = new TeleportJob(player, npc, teleportLoc, origin, true); JobScheduler.getInstance().scheduleJob(tj, time * 1000); } else if (joinedGuild) { - player.teleport(teleportLoc); + PlayerManager.teleport(player, teleportLoc); player.setSafeMode(); } } diff --git a/src/engine/net/client/handlers/ObjectActionMsgHandler.java b/src/engine/net/client/handlers/ObjectActionMsgHandler.java index dafcb0da..a599d8d0 100644 --- a/src/engine/net/client/handlers/ObjectActionMsgHandler.java +++ b/src/engine/net/client/handlers/ObjectActionMsgHandler.java @@ -417,7 +417,7 @@ public class ObjectActionMsgHandler extends AbstractClientMsgHandler { if (!toCommand.isSiege()) return true; - if (player.commandSiegeMinion(toCommand)) { + if (PlayerManager.commandSiegeMinion(player, toCommand)) { itemMan.consume(item); } break; diff --git a/src/engine/net/client/handlers/OpenFriendsCondemnListMsgHandler.java b/src/engine/net/client/handlers/OpenFriendsCondemnListMsgHandler.java index ccb93609..b8dab27e 100644 --- a/src/engine/net/client/handlers/OpenFriendsCondemnListMsgHandler.java +++ b/src/engine/net/client/handlers/OpenFriendsCondemnListMsgHandler.java @@ -6,6 +6,7 @@ import engine.Enum.GameObjectType; import engine.exception.MsgSendException; import engine.gameManager.BuildingManager; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.gameManager.SessionManager; import engine.net.Dispatch; import engine.net.DispatchMessage; @@ -71,7 +72,7 @@ public class OpenFriendsCondemnListMsgHandler extends AbstractClientMsgHandler { } AbstractCharacter toAdd = null; if (msg.getPlayerType() == GameObjectType.PlayerCharacter.ordinal()) - toAdd = PlayerCharacter.getFromCache(msg.getPlayerID()); + toAdd = PlayerManager.getFromCache(msg.getPlayerID()); else if (msg.getPlayerType() == GameObjectType.NPC.ordinal()) toAdd = NPC.getFromCache(msg.getPlayerID()); else if (msg.getPlayerType() == GameObjectType.Mob.ordinal()) @@ -214,7 +215,7 @@ public class OpenFriendsCondemnListMsgHandler extends AbstractClientMsgHandler { if (msg.getPlayerType() != GameObjectType.PlayerCharacter.ordinal()) return true; - PlayerCharacter playerCharacter = PlayerCharacter.getFromCache(msg.getPlayerID()); + PlayerCharacter playerCharacter = PlayerManager.getFromCache(msg.getPlayerID()); if (playerCharacter == null) return true; @@ -303,7 +304,7 @@ public class OpenFriendsCondemnListMsgHandler extends AbstractClientMsgHandler { //Check to see if the invited is already on the friends list. switch (msg.getInviteType()) { case 7: - playerCharacter = PlayerCharacter.getFromCache(msg.getPlayerID()); + playerCharacter = PlayerManager.getFromCache(msg.getPlayerID()); if (playerCharacter == null) return true; if (sourceBuilding.getFriends().containsKey(playerCharacter.getObjectUUID())) diff --git a/src/engine/net/client/handlers/RequestEnterWorldHandler.java b/src/engine/net/client/handlers/RequestEnterWorldHandler.java index 18b48254..26d26536 100644 --- a/src/engine/net/client/handlers/RequestEnterWorldHandler.java +++ b/src/engine/net/client/handlers/RequestEnterWorldHandler.java @@ -8,6 +8,7 @@ import engine.db.archive.CharacterRecord; import engine.db.archive.DataWarehouse; import engine.db.archive.PvpRecord; import engine.exception.MsgSendException; +import engine.gameManager.PlayerManager; import engine.gameManager.SessionManager; import engine.math.Vector3fImmutable; import engine.net.Dispatch; @@ -57,7 +58,7 @@ public class RequestEnterWorldHandler extends AbstractClientMsgHandler { return true; } - player.setEnteredWorld(false); + PlayerManager.setEnteredWorld(player, false); Account acc = SessionManager.getAccount(origin); @@ -118,7 +119,7 @@ public class RequestEnterWorldHandler extends AbstractClientMsgHandler { try { if (!player.isAlive()) { Logger.info("respawning player on enter world."); - player.respawn(true, true, true); + PlayerManager.respawn(player, true, true, true); } } catch (Exception e) { diff --git a/src/engine/net/client/handlers/SwearInHandler.java b/src/engine/net/client/handlers/SwearInHandler.java index 2796bbaa..867a2f66 100644 --- a/src/engine/net/client/handlers/SwearInHandler.java +++ b/src/engine/net/client/handlers/SwearInHandler.java @@ -12,6 +12,7 @@ package engine.net.client.handlers; import engine.Enum; import engine.exception.MsgSendException; import engine.gameManager.ChatManager; +import engine.gameManager.PlayerManager; import engine.gameManager.SessionManager; import engine.net.Dispatch; import engine.net.DispatchMessage; @@ -63,7 +64,7 @@ public class SwearInHandler extends AbstractClientMsgHandler { } // Swear target in and send message to guild - target.setFullMember(true); + PlayerManager.setFullMember(target, true); target.incVer(); ChatManager.chatGuildInfo(source, target.getFirstName() + " has been sworn in as a full member!"); diff --git a/src/engine/net/client/handlers/TransferAssetMsgHandler.java b/src/engine/net/client/handlers/TransferAssetMsgHandler.java index a9ccdc4e..ae87ea99 100644 --- a/src/engine/net/client/handlers/TransferAssetMsgHandler.java +++ b/src/engine/net/client/handlers/TransferAssetMsgHandler.java @@ -4,6 +4,7 @@ import engine.Enum; import engine.exception.MsgSendException; import engine.gameManager.BuildingManager; import engine.gameManager.ChatManager; +import engine.gameManager.PlayerManager; import engine.net.client.ClientConnection; import engine.net.client.msg.ClientNetMsg; import engine.net.client.msg.ErrorPopupMsg; @@ -35,7 +36,7 @@ public class TransferAssetMsgHandler extends AbstractClientMsgHandler { int TargetType = transferAssetMsg.getTargetType(); //ToDue later Building building = BuildingManager.getBuildingFromCache(Buildingid); - PlayerCharacter newOwner = PlayerCharacter.getFromCache(TargetID); + PlayerCharacter newOwner = PlayerManager.getFromCache(TargetID); PlayerCharacter player = origin.getPlayerCharacter(); if (player == null || building == null || newOwner == null) diff --git a/src/engine/net/client/msg/ApplyRuneMsg.java b/src/engine/net/client/msg/ApplyRuneMsg.java index 492f20f3..4b419d44 100644 --- a/src/engine/net/client/msg/ApplyRuneMsg.java +++ b/src/engine/net/client/msg/ApplyRuneMsg.java @@ -12,6 +12,7 @@ package engine.net.client.msg; import engine.Enum; import engine.gameManager.ChatManager; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.net.*; import engine.net.client.ClientConnection; import engine.net.client.Protocol; @@ -381,23 +382,23 @@ public class ApplyRuneMsg extends ClientNetMsg { //add any additional stats to match old amount int dif = strTotal - (int) playerCharacter.statStrBase; if (dif > 0 && strTotal < (int) playerCharacter.statStrMax) { - playerCharacter.addStr(dif); + PlayerManager.addStr(playerCharacter, dif); } dif = dexTotal - (int) playerCharacter.statDexBase; if (dif > 0 && dexTotal < (int) playerCharacter.statDexMax) { - playerCharacter.addDex(dif); + PlayerManager.addDex(playerCharacter, dif); } dif = conTotal - (int) playerCharacter.statConBase; if (dif > 0 && conTotal < (int) playerCharacter.statConMax) { - playerCharacter.addCon(dif); + PlayerManager.addCon(playerCharacter, dif); } dif = intTotal - (int) playerCharacter.statIntBase; if (dif > 0 && intTotal < (int) playerCharacter.statIntMax) { - playerCharacter.addInt(dif); + PlayerManager.addInt(playerCharacter, dif); } dif = spiTotal - (int) playerCharacter.statSpiBase; if (dif > 0 && spiTotal < (int) playerCharacter.statSpiMax) { - playerCharacter.addSpi(dif); + PlayerManager.addSpi(playerCharacter, dif); } // recalculate all bonuses/formulas/skills/powers playerCharacter.recalculate(); diff --git a/src/engine/net/client/msg/ArcViewAssetTransactionsMsg.java b/src/engine/net/client/msg/ArcViewAssetTransactionsMsg.java index af4cc873..cef8f67c 100644 --- a/src/engine/net/client/msg/ArcViewAssetTransactionsMsg.java +++ b/src/engine/net/client/msg/ArcViewAssetTransactionsMsg.java @@ -13,6 +13,7 @@ import engine.Enum.GameObjectType; import engine.Enum.TransactionType; import engine.exception.SerializationException; import engine.gameManager.BuildingManager; +import engine.gameManager.PlayerManager; import engine.net.AbstractConnection; import engine.net.ByteBufferReader; import engine.net.ByteBufferWriter; @@ -102,7 +103,7 @@ public class ArcViewAssetTransactionsMsg extends ClientNetMsg { break; case PlayerCharacter: - PlayerCharacter pc = PlayerCharacter.getPlayerCharacter(transaction.getTargetUUID()); + PlayerCharacter pc = PlayerManager.getPlayerCharacter(transaction.getTargetUUID()); if (pc != null) name = pc.getCombinedName(); break; diff --git a/src/engine/net/client/msg/BuyFromNPCWindowMsg.java b/src/engine/net/client/msg/BuyFromNPCWindowMsg.java index 50654f21..259ae088 100644 --- a/src/engine/net/client/msg/BuyFromNPCWindowMsg.java +++ b/src/engine/net/client/msg/BuyFromNPCWindowMsg.java @@ -11,6 +11,7 @@ package engine.net.client.msg; import engine.Enum.ItemType; import engine.exception.SerializationException; +import engine.gameManager.PlayerManager; import engine.net.AbstractConnection; import engine.net.AbstractNetMsg; import engine.net.ByteBufferReader; @@ -100,7 +101,7 @@ public class BuyFromNPCWindowMsg extends ClientNetMsg { man = npc.getCharItemManager(); Contract contract = npc.getContract(); if (player != null) { - float barget = player.getBargain(); + float barget = PlayerManager.getBargain(player); float profit = npc.getSellPercent(player) - barget; if (profit < 1) diff --git a/src/engine/net/client/msg/IgnoreMsg.java b/src/engine/net/client/msg/IgnoreMsg.java index 644f8b45..c8d552fd 100644 --- a/src/engine/net/client/msg/IgnoreMsg.java +++ b/src/engine/net/client/msg/IgnoreMsg.java @@ -12,6 +12,7 @@ package engine.net.client.msg; import engine.gameManager.ChatManager; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.gameManager.SessionManager; import engine.net.AbstractConnection; import engine.net.ByteBufferReader; @@ -81,7 +82,7 @@ public class IgnoreMsg extends ClientNetMsg { } //FIX THIS, USE OUR CACHE! - PlayerCharacter pcToIgnore = PlayerCharacter.getByFirstName(nameToIgnore); + PlayerCharacter pcToIgnore = PlayerManager.getByFirstName(nameToIgnore); if (pcSource == null) { return; @@ -114,11 +115,11 @@ public class IgnoreMsg extends ClientNetMsg { pcSource.removeIgnoredPlayer(pcToIgnore.getAccount()); ChatManager.chatSystemInfo(pcSource, "Character " + fn + " is no longer ignored."); } else { - if (!PlayerCharacter.isIgnorable()) { + if (!PlayerManager.isIgnorable()) { ChatManager.chatSystemError(pcSource, "This character cannot be ignored."); return; } - if (PlayerCharacter.isIgnoreListFull()) { + if (PlayerManager.isIgnoreListFull()) { ChatManager.chatSystemError(pcSource, "Your ignore list is already full."); return; } diff --git a/src/engine/net/client/msg/OpenFriendsCondemnListMsg.java b/src/engine/net/client/msg/OpenFriendsCondemnListMsg.java index f6eaefad..590e18c8 100644 --- a/src/engine/net/client/msg/OpenFriendsCondemnListMsg.java +++ b/src/engine/net/client/msg/OpenFriendsCondemnListMsg.java @@ -11,6 +11,7 @@ package engine.net.client.msg; import engine.Enum.GameObjectType; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.net.AbstractConnection; import engine.net.ByteBufferReader; import engine.net.ByteBufferWriter; @@ -619,7 +620,7 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg { writer.putInt(listSize); for (BuildingFriends friend : this.friends.values()) { - pc = PlayerCharacter.getFromCache(friend.getPlayerUID()); + pc = PlayerManager.getFromCache(friend.getPlayerUID()); guild = Guild.getGuild(friend.getGuildUID()); if (friend.getFriendType() == 7) { if (pc != null) @@ -718,7 +719,7 @@ public class OpenFriendsCondemnListMsg extends ClientNetMsg { AbstractCharacter heraldryCharacter = null; int characterType = heraldryMap.get(characterID); if (characterType == GameObjectType.PlayerCharacter.ordinal()) - heraldryCharacter = PlayerCharacter.getFromCache(characterID); + heraldryCharacter = PlayerManager.getFromCache(characterID); else if (characterType == GameObjectType.NPC.ordinal()) heraldryCharacter = NPC.getFromCache(characterID); else if (characterType == GameObjectType.Mob.ordinal()) diff --git a/src/engine/net/client/msg/RefineMsg.java b/src/engine/net/client/msg/RefineMsg.java index 81968961..24e59364 100644 --- a/src/engine/net/client/msg/RefineMsg.java +++ b/src/engine/net/client/msg/RefineMsg.java @@ -10,6 +10,7 @@ package engine.net.client.msg; +import engine.gameManager.PlayerManager; import engine.gameManager.SessionManager; import engine.net.*; import engine.net.client.ClientConnection; @@ -160,15 +161,15 @@ public class RefineMsg extends ClientNetMsg { private static boolean refineStat(ClientConnection origin, PlayerCharacter pc, int token, RefineMsg msg) { if (token == MBServerStatics.STAT_STR_ID) - return pc.refineStr(); + return PlayerManager.refineStr(pc); if (token == MBServerStatics.STAT_DEX_ID) - return pc.refineDex(); + return PlayerManager.refineDex(pc); if (token == MBServerStatics.STAT_CON_ID) - return pc.refineCon(); + return PlayerManager.refineCon(pc); if (token == MBServerStatics.STAT_INT_ID) - return pc.refineInt(msg); + return PlayerManager.refineInt(pc, msg); if (token == MBServerStatics.STAT_SPI_ID) - return pc.refineSpi(); + return PlayerManager.refineSpi(pc); return false; } diff --git a/src/engine/net/client/msg/SendOwnPlayerMsg.java b/src/engine/net/client/msg/SendOwnPlayerMsg.java index f83f0dc1..9e277738 100644 --- a/src/engine/net/client/msg/SendOwnPlayerMsg.java +++ b/src/engine/net/client/msg/SendOwnPlayerMsg.java @@ -11,6 +11,7 @@ package engine.net.client.msg; import engine.exception.SerializationException; +import engine.gameManager.PlayerManager; import engine.net.AbstractConnection; import engine.net.AbstractNetMsg; import engine.net.ByteBufferReader; @@ -90,7 +91,7 @@ public class SendOwnPlayerMsg extends ClientNetMsg { } writer.putVector3f(ch.getLoc()); try { - PlayerCharacter.serializeForClientMsgFull(this.ch, writer); + PlayerManager.serializeForClientMsgFull(this.ch, writer); } catch (SerializationException e) { Logger.error(e); } diff --git a/src/engine/net/client/msg/TerritoryChangeMessage.java b/src/engine/net/client/msg/TerritoryChangeMessage.java index 87e811b0..5019b48b 100644 --- a/src/engine/net/client/msg/TerritoryChangeMessage.java +++ b/src/engine/net/client/msg/TerritoryChangeMessage.java @@ -11,6 +11,7 @@ package engine.net.client.msg; import engine.exception.SerializationException; +import engine.gameManager.PlayerManager; import engine.net.AbstractConnection; import engine.net.ByteBufferReader; import engine.net.ByteBufferWriter; @@ -64,7 +65,7 @@ public class TerritoryChangeMessage extends ClientNetMsg { writer.putString(realm.getRealmName()); if (this.realmOwner != null) { writer.putString(this.realmOwner.getCombinedName()); - writer.putInt(PlayerCharacter.GetPlayerRealmTitle(this.realmOwner)); + writer.putInt(PlayerManager.GetPlayerRealmTitle(this.realmOwner)); writer.putInt(1); writer.put((byte) 1); writer.put((byte) 1); diff --git a/src/engine/net/client/msg/TrackWindowMsg.java b/src/engine/net/client/msg/TrackWindowMsg.java index 7b647ee9..02f88e38 100644 --- a/src/engine/net/client/msg/TrackWindowMsg.java +++ b/src/engine/net/client/msg/TrackWindowMsg.java @@ -10,6 +10,7 @@ package engine.net.client.msg; import engine.Enum.GameObjectType; +import engine.gameManager.PlayerManager; import engine.net.AbstractConnection; import engine.net.AbstractNetMsg; import engine.net.ByteBufferReader; @@ -89,7 +90,7 @@ public class TrackWindowMsg extends ClientNetMsg { for (int i = 0; i < size; i++) { int objectType = reader.getInt(); int objectID = reader.getInt(); - this.source = PlayerCharacter.getFromCache(objectID); + this.source = PlayerManager.getFromCache(objectID); reader.getString(); //name reader.get(); //always 00? reader.getInt(); //guildObjectType @@ -106,7 +107,7 @@ public class TrackWindowMsg extends ClientNetMsg { //Get the Character from it's Object Type and ID AbstractCharacter ac = null; if (objectType == GameObjectType.PlayerCharacter.ordinal()) - ac = PlayerCharacter.getFromCache(objectID); + ac = PlayerManager.getFromCache(objectID); else if (objectType == GameObjectType.NPC.ordinal()) ac = NPC.getFromCache(objectID); else if (objectType == GameObjectType.Mob.ordinal()) diff --git a/src/engine/net/client/msg/VendorDialogMsg.java b/src/engine/net/client/msg/VendorDialogMsg.java index 941c07b8..46c078a2 100644 --- a/src/engine/net/client/msg/VendorDialogMsg.java +++ b/src/engine/net/client/msg/VendorDialogMsg.java @@ -12,10 +12,7 @@ package engine.net.client.msg; import engine.Enum.DispatchChannel; import engine.Enum.GuildHistoryType; import engine.exception.MsgSendException; -import engine.gameManager.BuildingManager; -import engine.gameManager.DbManager; -import engine.gameManager.GuildManager; -import engine.gameManager.SessionManager; +import engine.gameManager.*; import engine.math.Vector3fImmutable; import engine.net.*; import engine.net.client.ClientConnection; @@ -437,7 +434,7 @@ public class VendorDialogMsg extends ClientNetMsg { if (level >= minLevel && level <= maxLevel) { if (useSquare) loc = getSquare(loc); - pc.teleport(loc); + PlayerManager.teleport(pc, loc); pc.setSafeMode(); // PowersManager.applyPower(pc, pc, new Vector3f(0f, // 0f, 0f), -1661758934, 40, false); @@ -463,7 +460,7 @@ public class VendorDialogMsg extends ClientNetMsg { // teleport player if (useSquare) loc = getSquare(loc); - pc.teleport(loc); + PlayerManager.teleport(pc, loc); pc.setSafeMode(); // PowersManager.applyPower(pc, pc, new // Vector3f(0f, 0f, 0f), -1661758934, 40, false); @@ -471,10 +468,10 @@ public class VendorDialogMsg extends ClientNetMsg { // join guild GuildManager.joinGuild(pc, guild, GuildHistoryType.JOIN); - pc.resetGuildStatuses(); + PlayerManager.resetGuildStatuses(pc); if (guild.isNPCGuild()) - pc.setFullMember(true); + PlayerManager.setFullMember(pc, true); if (useSquare) loc = loc.add(30, 0, 0); @@ -483,7 +480,7 @@ public class VendorDialogMsg extends ClientNetMsg { // guild not found, just teleport if (useSquare) loc = getSquare(loc); - pc.teleport(loc); + PlayerManager.teleport(pc, loc); pc.setSafeMode(); // PowersManager.applyPower(pc, pc, new // Vector3f(0f, 0f, 0f), -1661758934, 50, false); diff --git a/src/engine/net/client/msg/WhoResponseMsg.java b/src/engine/net/client/msg/WhoResponseMsg.java index dc27c00b..7cfd38e1 100644 --- a/src/engine/net/client/msg/WhoResponseMsg.java +++ b/src/engine/net/client/msg/WhoResponseMsg.java @@ -10,6 +10,7 @@ package engine.net.client.msg; import engine.Enum; +import engine.gameManager.PlayerManager; import engine.gameManager.SessionManager; import engine.net.*; import engine.net.client.ClientConnection; @@ -233,8 +234,8 @@ public class WhoResponseMsg extends ClientNetMsg { writer.putInt(pc.getObjectUUID()); writer.putString(pc.getFirstName()); writer.putString(pc.getLastName()); - writer.putInt(pc.getRaceToken()); - writer.putInt(pc.getClassToken()); + writer.putInt(PlayerManager.getRaceToken(pc)); + writer.putInt(PlayerManager.getClassToken(pc)); writer.putInt(pc.getLevel()); writer.putInt(0); // unknown 0 writer.putInt(pc.isMale() ? 1 : 2); //gender? diff --git a/src/engine/net/client/msg/guild/GuildInfoMsg.java b/src/engine/net/client/msg/guild/GuildInfoMsg.java index aea3c464..0229378c 100644 --- a/src/engine/net/client/msg/guild/GuildInfoMsg.java +++ b/src/engine/net/client/msg/guild/GuildInfoMsg.java @@ -11,6 +11,7 @@ package engine.net.client.msg.guild; import engine.Enum.GameObjectType; +import engine.gameManager.PlayerManager; import engine.net.AbstractConnection; import engine.net.ByteBufferReader; import engine.net.ByteBufferWriter; @@ -193,7 +194,7 @@ class GuildInfoMessageType2 extends GuildInfoMessageType { writer.putString(g.getName()); if (this.objectType == GameObjectType.PlayerCharacter.ordinal()) { - PlayerCharacter pc = PlayerCharacter.getFromCache(this.objectID); + PlayerCharacter pc = PlayerManager.getFromCache(this.objectID); if (pc != null) { writer.putInt(GuildStatusController.getRank(pc.getGuildStatus())); @@ -254,7 +255,7 @@ class GuildInfoMessageType4 extends GuildInfoMessageType { writer.putInt(0); writer.putInt(0); writer.putInt(0); - PlayerCharacter pc = PlayerCharacter.getFromCache(this.objectID); + PlayerCharacter pc = PlayerManager.getFromCache(this.objectID); if (this.g == null || pc == null) { writer.putInt(0); writer.putInt(0); @@ -298,7 +299,7 @@ class GuildInfoMessageType4 extends GuildInfoMessageType { if (guildLeader != null) guildLeaderName = guildLeader.getName(); } else { - guildLeader = PlayerCharacter.getFromCache(g.getGuildLeaderUUID()); + guildLeader = PlayerManager.getFromCache(g.getGuildLeaderUUID()); if (guildLeader != null) guildLeaderName = ((PlayerCharacter) guildLeader).getCombinedName(); } diff --git a/src/engine/net/client/msg/guild/GuildListMsg.java b/src/engine/net/client/msg/guild/GuildListMsg.java index f40783be..935c89dd 100644 --- a/src/engine/net/client/msg/guild/GuildListMsg.java +++ b/src/engine/net/client/msg/guild/GuildListMsg.java @@ -11,6 +11,7 @@ package engine.net.client.msg.guild; import engine.Enum; import engine.Enum.GameObjectType; +import engine.gameManager.PlayerManager; import engine.gameManager.SessionManager; import engine.net.AbstractConnection; import engine.net.ByteBufferReader; @@ -204,7 +205,7 @@ class GuildListMessageType2 extends GuildListMessageType { writer.putInt(GuildStatusController.getTitle(pc.getGuildStatus())); //Title Maybe? writer.putInt(GuildStatusController.getRank(pc.getGuildStatus())); //Rank? - writer.putInt(pc.getRaceToken()); //race token + writer.putInt(PlayerManager.getRaceToken(pc)); //race token writer.putInt(pc.getBaseClassToken()); //class token writer.putInt(2); //PAD diff --git a/src/engine/net/client/msg/login/CharSelectScreenMsg.java b/src/engine/net/client/msg/login/CharSelectScreenMsg.java index 34fd3f32..ebdd14e8 100644 --- a/src/engine/net/client/msg/login/CharSelectScreenMsg.java +++ b/src/engine/net/client/msg/login/CharSelectScreenMsg.java @@ -11,6 +11,7 @@ package engine.net.client.msg.login; import engine.exception.SerializationException; +import engine.gameManager.PlayerManager; import engine.net.AbstractConnection; import engine.net.AbstractNetMsg; import engine.net.ByteBufferReader; @@ -162,9 +163,9 @@ public class CharSelectScreenMsg extends ClientNetMsg { for (int i = 0; i < this.numChars; ++i) { try { if (!fromCommit) - PlayerCharacter.serializeForClientMsgLogin(this.chars.get(i), writer); + PlayerManager.serializeForClientMsgLogin(this.chars.get(i), writer); else - PlayerCharacter.serializeForClientMsgCommit(this.chars.get(i), writer); + PlayerManager.serializeForClientMsgCommit(this.chars.get(i), writer); } catch (SerializationException e) { Logger.error("failed to serialize character " + this.chars.get(i).getObjectUUID()); // Handled already. diff --git a/src/engine/objects/AbstractCharacter.java b/src/engine/objects/AbstractCharacter.java index 3c942a8f..3ed9e109 100644 --- a/src/engine/objects/AbstractCharacter.java +++ b/src/engine/objects/AbstractCharacter.java @@ -57,7 +57,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject { protected short statIntCurrent; protected short statSpiCurrent; protected short unusedStatPoints; - protected int exp; + public int exp; public int buildingUUID; public Building building; @@ -67,8 +67,8 @@ public abstract class AbstractCharacter extends AbstractWorldObject { public int guildUUID; public Guild guild; protected byte runningTrains; - protected ConcurrentHashMap powers; - protected ConcurrentHashMap skills; + public ConcurrentHashMap powers; + public ConcurrentHashMap skills; // Variables NOT to be stored in db protected boolean sit = false; protected boolean walkMode; @@ -80,11 +80,11 @@ public abstract class AbstractCharacter extends AbstractWorldObject { // ticking down so that mobs/players following dont just move away to your projected location protected Vector3fImmutable nextEndLoc = Vector3fImmutable.ZERO; protected float speed; - protected AtomicFloat stamina = new AtomicFloat(); + public AtomicFloat stamina = new AtomicFloat(); protected float staminaMax; - protected AtomicFloat mana = new AtomicFloat(); + public AtomicFloat mana = new AtomicFloat(); protected float manaMax; // Health/Mana/Stamina - protected AtomicBoolean isAlive = new AtomicBoolean(true); + public AtomicBoolean isAlive = new AtomicBoolean(true); protected Resists resists = new Resists("Genric"); protected ConcurrentHashMap timers; protected ConcurrentHashMap timestamps; @@ -102,7 +102,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject { protected boolean isActive; // <-Do not use this for deleting character! protected float altitude = 0; // 0=on terrain, 1=tier 1, 2=tier 2, etc. protected ConcurrentHashMap recycleTimers; - protected PlayerBonuses bonuses; + public PlayerBonuses bonuses; protected JobContainer lastChant; protected boolean isCasting = false; protected long lastSetLocUpdate = 0L; @@ -363,7 +363,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject { switch (abstractCharacter.getObjectType()) { case PlayerCharacter: - PlayerCharacter.serializePlayerForClientMsgOtherPlayer((PlayerCharacter) abstractCharacter, writer, asciiLastName); + PlayerManager.serializePlayerForClientMsgOtherPlayer((PlayerCharacter) abstractCharacter, writer, asciiLastName); break; case Mob: Mob.serializeMobForClientMsgOtherPlayer((Mob) abstractCharacter, writer); @@ -445,7 +445,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject { playerCharacter.calculateItemBonuses(); //recalculate formulas - PlayerCharacter.recalculatePlayerStatsOnLoad(playerCharacter); + PlayerManager.recalculatePlayerStatsOnLoad(playerCharacter); } catch (Exception e) { Logger.error(e); @@ -746,7 +746,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject { } if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) - if (((PlayerCharacter) this).isLastSwimming()) + if (PlayerManager.isLastSwimming(((PlayerCharacter) this))) return 1; //swimming return 2; //ground @@ -1707,7 +1707,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject { if (CanFly(player) == false && player.getMovementState().equals(MovementState.FLYING)) - PlayerCharacter.GroundPlayer(player); + PlayerManager.GroundPlayer(player); } } catch (Exception e) { diff --git a/src/engine/objects/AbstractGameObject.java b/src/engine/objects/AbstractGameObject.java index b105cf14..e49a360e 100644 --- a/src/engine/objects/AbstractGameObject.java +++ b/src/engine/objects/AbstractGameObject.java @@ -12,6 +12,7 @@ package engine.objects; import engine.Enum.GameObjectType; import engine.gameManager.BuildingManager; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.job.JobContainer; import engine.job.JobScheduler; import engine.jobs.DatabaseUpdateJob; @@ -107,7 +108,7 @@ public abstract class AbstractGameObject { switch (objectType) { case PlayerCharacter: - return PlayerCharacter.getPlayerCharacter(tableID); + return PlayerManager.getPlayerCharacter(tableID); case NPC: return NPC.getNPC(tableID); diff --git a/src/engine/objects/AbstractWorldObject.java b/src/engine/objects/AbstractWorldObject.java index ac06b52a..be1a6ca1 100644 --- a/src/engine/objects/AbstractWorldObject.java +++ b/src/engine/objects/AbstractWorldObject.java @@ -15,6 +15,7 @@ import engine.Enum.GameObjectType; import engine.Enum.GridObjectType; import engine.InterestManagement.HeightMap; import engine.InterestManagement.WorldGrid; +import engine.gameManager.PlayerManager; import engine.job.AbstractScheduleJob; import engine.job.JobContainer; import engine.job.JobScheduler; @@ -39,7 +40,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; public abstract class AbstractWorldObject extends AbstractGameObject { - protected final ReadWriteLock locationLock = new ReentrantReadWriteLock(true); + public final ReadWriteLock locationLock = new ReentrantReadWriteLock(true); protected final ReadWriteLock updateLock = new ReentrantReadWriteLock(true); public float healthMax; public ConcurrentHashMap effects = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); @@ -49,7 +50,7 @@ public abstract class AbstractWorldObject extends AbstractGameObject { public Regions landingRegion = null; public Vector3fImmutable lastLoc = Vector3fImmutable.ZERO; public Vector3fImmutable loc = new Vector3fImmutable(0.0f, 0.0f, 0.0f); - protected AtomicFloat health = new AtomicFloat(); + public AtomicFloat health = new AtomicFloat(); protected boolean load = true; protected GridObjectType gridObjectType; protected float altitude = 0; @@ -150,7 +151,7 @@ public abstract class AbstractWorldObject extends AbstractGameObject { Regions region = null; if (worldObject.getObjectType().equals(GameObjectType.PlayerCharacter)) - if (((PlayerCharacter) worldObject).isFlying()) + if (PlayerManager.isFlying(((PlayerCharacter) worldObject))) return null; //Find building for (AbstractWorldObject awo : WorldGrid.getObjectsInRangePartial(worldObject.getLoc(), MBServerStatics.STRUCTURE_LOAD_RANGE, MBServerStatics.MASK_BUILDING)) { @@ -271,7 +272,7 @@ public abstract class AbstractWorldObject extends AbstractGameObject { if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) if (name.equals("Flight")) { ((PlayerCharacter) this).update(false); - PlayerCharacter.GroundPlayer((PlayerCharacter) this); + PlayerManager.GroundPlayer((PlayerCharacter) this); } } applyAllBonuses(); @@ -386,7 +387,7 @@ public abstract class AbstractWorldObject extends AbstractGameObject { //ground player if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) { ((PlayerCharacter) this).update(false); - PlayerCharacter.GroundPlayer((PlayerCharacter) this); + PlayerManager.GroundPlayer((PlayerCharacter) this); } } } else { @@ -415,7 +416,7 @@ public abstract class AbstractWorldObject extends AbstractGameObject { //ground player if (this.getObjectType().equals(GameObjectType.PlayerCharacter)) { ((PlayerCharacter) this).update(false); - PlayerCharacter.GroundPlayer((PlayerCharacter) this); + PlayerManager.GroundPlayer((PlayerCharacter) this); } } diff --git a/src/engine/objects/Account.java b/src/engine/objects/Account.java index 7beb72b5..3090dafd 100644 --- a/src/engine/objects/Account.java +++ b/src/engine/objects/Account.java @@ -14,6 +14,7 @@ import engine.Enum.DispatchChannel; import engine.Enum.ItemContainerType; import engine.gameManager.ConfigManager; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.gameManager.SessionManager; import engine.net.Dispatch; import engine.net.DispatchMessage; @@ -163,7 +164,7 @@ public class Account extends AbstractGameObject { ArrayList playerList = DbManager.PlayerCharacterQueries.GET_CHARACTERS_FOR_ACCOUNT(this.getObjectUUID()); for (PlayerCharacter player : playerList) { - PlayerCharacter.initializePlayer(player); + PlayerManager.initializePlayer(player); this.characterMap.putIfAbsent(player.getObjectUUID(), player); } diff --git a/src/engine/objects/Bane.java b/src/engine/objects/Bane.java index b59acff0..094705a3 100644 --- a/src/engine/objects/Bane.java +++ b/src/engine/objects/Bane.java @@ -261,7 +261,7 @@ public final class Bane { Vector3fImmutable movePlayerOutsideStone = player.getLoc(); movePlayerOutsideStone = movePlayerOutsideStone.setX(movePlayerOutsideStone.x + 10); movePlayerOutsideStone = movePlayerOutsideStone.setZ(movePlayerOutsideStone.z + 10); - player.teleport(movePlayerOutsideStone); + PlayerManager.teleport(player, movePlayerOutsideStone); // Notify players @@ -734,7 +734,7 @@ public final class Bane { HashSet inSiegeRange = WorldGrid.getObjectsInRangePartial(city.getTOL().loc,1750f,1); for(AbstractWorldObject obj : inSiegeRange){ int uuid = obj.getObjectUUID(); - PlayerCharacter player = PlayerCharacter.getPlayerCharacter(uuid); + PlayerCharacter player = PlayerManager.getPlayerCharacter(uuid); if(player == null) continue; Guild playerNation = player.guild.getNation(); @@ -749,7 +749,7 @@ public final class Bane { int attackerSize = 0; int defenderSize = 0; for(int uuid : city.baneAttendees.keySet()){ - PlayerCharacter player = PlayerCharacter.getPlayerCharacter(uuid); + PlayerCharacter player = PlayerManager.getPlayerCharacter(uuid); if(player == null) continue; if(player.guild.getNation().equals(defendNation)) @@ -762,7 +762,7 @@ public final class Bane { float attackerMultiplier = ZergManager.getCurrentMultiplier(attackerSize,this.capSize); float defenderMultiplier = ZergManager.getCurrentMultiplier(defenderSize,this.capSize); for(int uuid : attackers){ - PlayerCharacter player = PlayerCharacter.getPlayerCharacter(uuid); + PlayerCharacter player = PlayerManager.getPlayerCharacter(uuid); if(inSiegeRange.contains(player)) //player is still physically here, needs updated multiplier player.ZergMultiplier = attackerMultiplier; else @@ -770,7 +770,7 @@ public final class Bane { } for(int uuid : defenders){ - PlayerCharacter player = PlayerCharacter.getPlayerCharacter(uuid); + PlayerCharacter player = PlayerManager.getPlayerCharacter(uuid); if(inSiegeRange.contains(player)) //player is still physically here, needs updated multiplier player.ZergMultiplier = defenderMultiplier; else diff --git a/src/engine/objects/Building.java b/src/engine/objects/Building.java index 6a54b8c9..9d79e400 100644 --- a/src/engine/objects/Building.java +++ b/src/engine/objects/Building.java @@ -19,6 +19,7 @@ import engine.db.archive.DataWarehouse; import engine.db.archive.MineRecord; import engine.gameManager.BuildingManager; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.gameManager.ZoneManager; import engine.job.JobContainer; import engine.job.JobScheduler; @@ -970,7 +971,7 @@ public class Building extends AbstractWorldObject { if (this.ownerIsNPC) return NPC.getFromCache(this.ownerUUID); - return PlayerCharacter.getFromCache(this.ownerUUID); + return PlayerManager.getFromCache(this.ownerUUID); } @@ -1095,7 +1096,7 @@ public class Building extends AbstractWorldObject { Logger.info("Building UID " + this.getObjectUUID() + " Failed to Load NPC Owner with ID " + this.ownerUUID + " Location " + this.getLoc().toString()); } else if (this.ownerUUID != 0) { - if (PlayerCharacter.getPlayerCharacter(this.ownerUUID) == null) { + if (PlayerManager.getPlayerCharacter(this.ownerUUID) == null) { Logger.info("Building UID " + this.getObjectUUID() + " Failed to Load Player Owner with ID " + this.ownerUUID + " Location " + this.getLoc().toString()); } } diff --git a/src/engine/objects/CharacterItemManager.java b/src/engine/objects/CharacterItemManager.java index cde911e6..c70d7541 100644 --- a/src/engine/objects/CharacterItemManager.java +++ b/src/engine/objects/CharacterItemManager.java @@ -12,10 +12,7 @@ package engine.objects; import engine.Enum; import engine.Enum.GameObjectType; import engine.Enum.ItemType; -import engine.gameManager.BuildingManager; -import engine.gameManager.ChatManager; -import engine.gameManager.ConfigManager; -import engine.gameManager.DbManager; +import engine.gameManager.*; import engine.math.Vector3fImmutable; import engine.net.Dispatch; import engine.net.DispatchMessage; @@ -424,7 +421,7 @@ public class CharacterItemManager { public synchronized boolean tradeRequest(TradeRequestMsg msg) { PlayerCharacter source = (PlayerCharacter) this.getOwner(); - PlayerCharacter target = PlayerCharacter.getFromCache(msg.getPlayerID()); + PlayerCharacter target = PlayerManager.getFromCache(msg.getPlayerID()); Dispatch dispatch; if (!canTrade(source, target)) { @@ -450,7 +447,7 @@ public class CharacterItemManager { } public synchronized boolean invalidTradeRequest(InvalidTradeRequestMsg msg) { - PlayerCharacter requester = PlayerCharacter.getFromCache(msg.getRequesterID()); + PlayerCharacter requester = PlayerManager.getFromCache(msg.getRequesterID()); Dispatch dispatch; dispatch = Dispatch.borrow(requester, msg); @@ -495,7 +492,7 @@ public class CharacterItemManager { public synchronized boolean acceptTradeRequest(AcceptTradeRequestMsg msg) { PlayerCharacter source = (PlayerCharacter) this.getOwner(); - PlayerCharacter target = PlayerCharacter.getFromCache(msg.getTargetID()); + PlayerCharacter target = PlayerManager.getFromCache(msg.getTargetID()); Dispatch dispatch; diff --git a/src/engine/objects/CharacterPower.java b/src/engine/objects/CharacterPower.java index c220438f..f071f4b1 100644 --- a/src/engine/objects/CharacterPower.java +++ b/src/engine/objects/CharacterPower.java @@ -10,6 +10,7 @@ package engine.objects; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.gameManager.PowersManager; import engine.net.ByteBufferWriter; import engine.net.client.msg.ErrorPopupMsg; @@ -90,7 +91,7 @@ public class CharacterPower extends AbstractGameObject { } public static PlayerCharacter getOwner(CharacterPower cp) { - return PlayerCharacter.getFromCache(cp.ownerUID); + return PlayerManager.getFromCache(cp.ownerUID); } /* diff --git a/src/engine/objects/CharacterSkill.java b/src/engine/objects/CharacterSkill.java index e4c4362a..f19e33d9 100644 --- a/src/engine/objects/CharacterSkill.java +++ b/src/engine/objects/CharacterSkill.java @@ -14,6 +14,7 @@ import engine.Enum.CharacterSkills; import engine.Enum.ModType; import engine.Enum.SourceType; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.net.ByteBufferWriter; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; @@ -287,7 +288,7 @@ public class CharacterSkill extends AbstractGameObject { if (cs.isMobOwner) return Mob.getFromCache(cs.ownerUID); else - return PlayerCharacter.getFromCache(cs.ownerUID); + return PlayerManager.getFromCache(cs.ownerUID); } /* diff --git a/src/engine/objects/City.java b/src/engine/objects/City.java index a115a4b2..cb376a07 100644 --- a/src/engine/objects/City.java +++ b/src/engine/objects/City.java @@ -694,7 +694,7 @@ public class City extends AbstractWorldObject { if (this.isNpc == 1) return NPC.getNPC(ownerID); else - return PlayerCharacter.getPlayerCharacter(ownerID); + return PlayerManager.getPlayerCharacter(ownerID); } public Guild getGuild() { @@ -882,7 +882,7 @@ public class City extends AbstractWorldObject { continue; player = (PlayerCharacter) playerObject; - player.addCityEffect(Integer.toString(effectBase.getUUID()), effectBase, rank, MBServerStatics.FOURTYFIVE_SECONDS, true, this); + PlayerManager.addCityEffect(player, Integer.toString(effectBase.getUUID()), effectBase, rank, MBServerStatics.FOURTYFIVE_SECONDS, true, this); } } @@ -903,7 +903,7 @@ public class City extends AbstractWorldObject { for (Integer playerID : this._playerMemory) { - player = PlayerCharacter.getFromCache(playerID); + player = PlayerManager.getFromCache(playerID); if (player == null) continue; @@ -912,7 +912,7 @@ public class City extends AbstractWorldObject { // Reapply effect with timeout? if (refreshEffect == true) - player.addCityEffect(Integer.toString(effectBase.getUUID()), effectBase, rank, MBServerStatics.FOURTYFIVE_SECONDS, false, this); + PlayerManager.addCityEffect(player, Integer.toString(effectBase.getUUID()), effectBase, rank, MBServerStatics.FOURTYFIVE_SECONDS, false, this); } @@ -969,7 +969,7 @@ public class City extends AbstractWorldObject { if (effectBase == null) continue; - player.addCityEffect(Integer.toString(effectBase.getUUID()), effectBase, effect.getTrains(), MBServerStatics.FOURTYFIVE_SECONDS, true, this); + PlayerManager.addCityEffect(player, Integer.toString(effectBase.getUUID()), effectBase, effect.getTrains(), MBServerStatics.FOURTYFIVE_SECONDS, true, this); } } catch (Exception e) { Logger.error(e.getMessage()); @@ -992,7 +992,7 @@ public class City extends AbstractWorldObject { return; // player.endEffectNoPower(cityEffect); - player.addCityEffect(Integer.toString(effectBase.getUUID()), effectBase, effect.getTrains(), MBServerStatics.FOURTYFIVE_SECONDS, false, this); + PlayerManager.addCityEffect(player, Integer.toString(effectBase.getUUID()), effectBase, effect.getTrains(), MBServerStatics.FOURTYFIVE_SECONDS, false, this); } } catch (Exception e) { Logger.error(e.getMessage()); @@ -1089,7 +1089,7 @@ public class City extends AbstractWorldObject { playerUUID = iter.next(); - player = PlayerCharacter.getFromCache(playerUUID); + player = PlayerManager.getFromCache(playerUUID); if (this.isLocationWithinSiegeBounds(player.getLoc())) continue; diff --git a/src/engine/objects/Contract.java b/src/engine/objects/Contract.java index f506d399..ab098081 100644 --- a/src/engine/objects/Contract.java +++ b/src/engine/objects/Contract.java @@ -242,7 +242,7 @@ public class Contract extends AbstractGameObject { } break; case 15020401: - PlayerCharacter.unboxPlayer(pc); + PlayerManager.unboxPlayer(pc); vd.getOptions().clear(); break; } diff --git a/src/engine/objects/Experience.java b/src/engine/objects/Experience.java index 8bd8c35c..04632cc2 100644 --- a/src/engine/objects/Experience.java +++ b/src/engine/objects/Experience.java @@ -11,6 +11,7 @@ package engine.objects; import engine.Enum; import engine.Enum.TargetColor; +import engine.gameManager.PlayerManager; import engine.gameManager.ZoneManager; import engine.math.Vector3fImmutable; import engine.server.MBServerStatics; @@ -444,7 +445,7 @@ public class Experience { grantedExperience = 1; // Grant the player the EXP - playerCharacter.grantXP((int) Math.floor(grantedExperience)); + PlayerManager.grantXP(playerCharacter, (int) Math.floor(grantedExperience)); } } else { // Give EXP to a single character @@ -471,7 +472,7 @@ public class Experience { grantedExperience *= .6; // Grant XP - killer.grantXP((int) Math.floor(grantedExperience)); + PlayerManager.grantXP(killer, (int) Math.floor(grantedExperience)); } } } diff --git a/src/engine/objects/Guild.java b/src/engine/objects/Guild.java index e1d39f40..6f8b785c 100644 --- a/src/engine/objects/Guild.java +++ b/src/engine/objects/Guild.java @@ -180,7 +180,7 @@ public class Guild extends AbstractWorldObject { if (guild.ownerIsNPC) return NPC.getFromCache(guild.guildLeaderUUID); - return PlayerCharacter.getFromCache(guild.guildLeaderUUID); + return PlayerManager.getFromCache(guild.guildLeaderUUID); } public static boolean sameGuild(Guild a, Guild b) { @@ -268,7 +268,7 @@ public class Guild extends AbstractWorldObject { writer.putInt(GuildStatusController.getTitle(pc.getGuildStatus())); // TODO Double check this is // title and rank if (GuildStatusController.isGuildLeader(pc.getGuildStatus())) - writer.putInt(PlayerCharacter.GetPlayerRealmTitle(pc)); + writer.putInt(PlayerManager.GetPlayerRealmTitle(pc)); else writer.putInt(GuildStatusController.getRank(pc.getGuildStatus())); //writer.putInt(GuildStatusController.getRank(pc.getGuildStatus())); @@ -576,14 +576,14 @@ public class Guild extends AbstractWorldObject { return false; } - PlayerCharacter oldGuildLeader = PlayerCharacter.getFromCache(this.guildLeaderUUID); + PlayerCharacter oldGuildLeader = PlayerManager.getFromCache(this.guildLeaderUUID); //old guildLeader no longer has guildLeadership stauts. if (oldGuildLeader != null) - oldGuildLeader.setGuildLeader(false); + PlayerManager.setGuildLeader(oldGuildLeader, false); if (ac.getObjectType().equals(GameObjectType.PlayerCharacter)) - ((PlayerCharacter) ac).setGuildLeader(true); + PlayerManager.setGuildLeader(((PlayerCharacter) ac), true); this.guildLeaderUUID = ac.getObjectUUID(); return true; @@ -597,7 +597,7 @@ public class Guild extends AbstractWorldObject { return false; if (ac.getObjectType().equals(GameObjectType.PlayerCharacter)) - ((PlayerCharacter) ac).setGuildLeader(true); + PlayerManager.setGuildLeader(((PlayerCharacter) ac), true); this.guildLeaderUUID = ac.getObjectUUID(); return true; @@ -665,7 +665,7 @@ public class Guild extends AbstractWorldObject { } // Clear Guild Ranks - pc.resetGuildStatuses(); + PlayerManager.resetGuildStatuses(pc); pc.setGuild(Guild.getErrantGuild()); pc.incVer(); @@ -835,7 +835,7 @@ public class Guild extends AbstractWorldObject { Logger.info("Guild UID " + this.getObjectUUID() + " Failed to Load NPC Owner with ID " + this.guildLeaderUUID); } else if (this.guildLeaderUUID != 0) { - if (PlayerCharacter.getPlayerCharacter(this.guildLeaderUUID) == null) + if (PlayerManager.getPlayerCharacter(this.guildLeaderUUID) == null) Logger.info("Guild UID " + this.getObjectUUID() + " Failed to Load Player Owner with ID " + this.guildLeaderUUID); } diff --git a/src/engine/objects/Heraldry.java b/src/engine/objects/Heraldry.java index b60fda8d..5134d0a2 100644 --- a/src/engine/objects/Heraldry.java +++ b/src/engine/objects/Heraldry.java @@ -11,6 +11,7 @@ package engine.objects; import engine.Enum.GameObjectType; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import org.pmw.tinylog.Logger; import java.sql.ResultSet; @@ -125,7 +126,7 @@ public class Heraldry { // Player is deleted, add to purge list - if (PlayerCharacter.getFromCache(characterID) == null) + if (PlayerManager.getFromCache(characterID) == null) purgeList.add(characterID); } diff --git a/src/engine/objects/Item.java b/src/engine/objects/Item.java index 050beb17..ea4507e9 100644 --- a/src/engine/objects/Item.java +++ b/src/engine/objects/Item.java @@ -14,6 +14,7 @@ import engine.Enum.*; import engine.exception.SerializationException; import engine.gameManager.ConfigManager; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.gameManager.PowersManager; import engine.net.ByteBufferReader; import engine.net.ByteBufferWriter; @@ -23,7 +24,6 @@ import engine.net.client.ClientConnection; import engine.net.client.msg.DeleteItemMsg; import engine.powers.EffectsBase; import engine.powers.effectmodifiers.AbstractEffectModifier; -import engine.powers.effectmodifiers.WeaponProcEffectModifier; import engine.powers.poweractions.AbstractPowerAction; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; @@ -287,7 +287,7 @@ public class Item extends AbstractWorldObject { boolean isBeard = (item.equipSlot == (byte) MBServerStatics.SLOT_BEARDSTYLE); int itemColor = 0; if (isHair || isBeard) { - PlayerCharacter pc = PlayerCharacter.getFromCache(item.ownerID); + PlayerCharacter pc = PlayerManager.getFromCache(item.ownerID); if (pc != null) if (isHair) itemColor = pc.getHairColor(); @@ -851,7 +851,7 @@ public class Item extends AbstractWorldObject { if (this.ownerType == OwnerType.Npc) return NPC.getFromCache(this.ownerID); else if (this.ownerType == OwnerType.PlayerCharacter) - return PlayerCharacter.getFromCache(this.ownerID); + return PlayerManager.getFromCache(this.ownerID); else if (this.ownerType == OwnerType.Mob) return Mob.getFromCache(this.ownerID); else if (this.ownerType == OwnerType.Account) diff --git a/src/engine/objects/Mine.java b/src/engine/objects/Mine.java index fa40fd5f..a77a75a6 100644 --- a/src/engine/objects/Mine.java +++ b/src/engine/objects/Mine.java @@ -10,11 +10,8 @@ package engine.objects; import engine.Enum; -import engine.InterestManagement.InterestManager; import engine.InterestManagement.WorldGrid; import engine.gameManager.*; -import engine.math.Vector3f; -import engine.math.Vector3fImmutable; import engine.net.ByteBufferWriter; import engine.net.client.msg.ErrorPopupMsg; import engine.server.MBServerStatics; @@ -27,7 +24,6 @@ import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.concurrent.ConcurrentHashMap; import static engine.gameManager.DbManager.MineQueries; @@ -677,7 +673,7 @@ public class Mine extends AbstractGameObject { ArrayListtoRemove = new ArrayList<>(); HashSet currentPlayers = WorldGrid.getObjectsInRangePartial(tower.loc, Enum.CityBoundsType.GRID.extents, MBServerStatics.MASK_PLAYER); for(Integer id : currentMemory){ - PlayerCharacter pc = PlayerCharacter.getPlayerCharacter(id); + PlayerCharacter pc = PlayerManager.getPlayerCharacter(id); if(currentPlayers.contains(pc) == false){ toRemove.add(id); pc.ZergMultiplier = 1.0f; diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index 240c3f3f..22801ac8 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -1130,7 +1130,7 @@ public class Mob extends AbstractIntelligenceAgent { if (this.ownerUID == 0) return null; - return PlayerCharacter.getFromCache(this.ownerUID); + return PlayerManager.getFromCache(this.ownerUID); } public void setOwner(PlayerCharacter value) { diff --git a/src/engine/objects/PlayerCharacter.java b/src/engine/objects/PlayerCharacter.java index fa1f9f62..6bc7d0f8 100644 --- a/src/engine/objects/PlayerCharacter.java +++ b/src/engine/objects/PlayerCharacter.java @@ -12,42 +12,26 @@ package engine.objects; import engine.Enum; import engine.Enum.*; import engine.InterestManagement.HeightMap; -import engine.InterestManagement.InterestManager; import engine.InterestManagement.RealmMap; import engine.InterestManagement.WorldGrid; import engine.db.archive.CharacterRecord; import engine.db.archive.DataWarehouse; import engine.db.archive.PvpRecord; -import engine.exception.MsgSendException; -import engine.exception.SerializationException; import engine.gameManager.*; -import engine.job.JobContainer; -import engine.job.JobScheduler; import engine.jobs.DeferredPowerJob; -import engine.jobs.FinishSpireEffectJob; -import engine.jobs.NoTimeJob; import engine.math.Bounds; import engine.math.FastMath; import engine.math.Vector3fImmutable; -import engine.net.ByteBufferWriter; import engine.net.Dispatch; import engine.net.DispatchMessage; import engine.net.client.ClientConnection; import engine.net.client.msg.*; -import engine.net.client.msg.login.CommitNewCharacterMsg; -import engine.powers.EffectsBase; import engine.server.MBServerStatics; -import engine.server.login.LoginServer; -import engine.server.login.LoginServerMsgHandler; -import engine.server.world.WorldServer; -import engine.util.MiscUtils; -import org.joda.time.DateTime; import org.pmw.tinylog.Logger; import java.sql.ResultSet; import java.sql.SQLException; import java.util.*; -import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.ReadWriteLock; @@ -60,7 +44,7 @@ public class PlayerCharacter extends AbstractCharacter { //any time the name of a PlayerCharacter needs to be set or //changed. It ensures the uniqueness check and subsequent //database update can happen exclusively. - private static final Object FirstNameLock = new Object(); + public static final Object FirstNameLock = new Object(); public final ReadWriteLock respawnLock = new ReentrantReadWriteLock(true); public final ArrayList necroPets = new ArrayList<>(); private final Account account; @@ -72,17 +56,17 @@ public class PlayerCharacter extends AbstractCharacter { private final byte beardStyle; //All Guild information should be held here private final AtomicInteger guildStatus; - private final AtomicInteger strMod = new AtomicInteger(); // Stat Modifiers - private final AtomicInteger dexMod = new AtomicInteger(); - private final AtomicInteger conMod = new AtomicInteger(); - private final AtomicInteger intMod = new AtomicInteger(); - private final AtomicInteger spiMod = new AtomicInteger(); + public final AtomicInteger strMod = new AtomicInteger(); // Stat Modifiers + public final AtomicInteger dexMod = new AtomicInteger(); + public final AtomicInteger conMod = new AtomicInteger(); + public final AtomicInteger intMod = new AtomicInteger(); + public final AtomicInteger spiMod = new AtomicInteger(); private final ReadWriteLock teleportLock = new ReentrantReadWriteLock(true); private final HashMap summoners = new HashMap<>(); private final HashSet loadedObjects = new HashSet<>(); private final ConcurrentHashMap> chatChanFloodList = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); private final ConcurrentHashMap killMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - private final AtomicInteger trainsAvailable = new AtomicInteger(0); // num skill trains not used + public final AtomicInteger trainsAvailable = new AtomicInteger(0); // num skill trains not used public boolean notDeleted; // <-Use this for deleting character // =========================================== @@ -119,15 +103,14 @@ public class PlayerCharacter extends AbstractCharacter { public FriendStatus friendStatus = FriendStatus.Available; protected ArrayList runes; private BaseClass baseClass; - private PromotionClass promotionClass; - private long channelMute = 0; // none muted. + public PromotionClass promotionClass; private ConcurrentHashMap ignoredPlayerIDs = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - private boolean lfGroup = false; - private boolean lfGuild = false; + private boolean lfGroup; + private boolean lfGuild; private boolean recruiting = false; private MovementState movementState = MovementState.IDLE; private MovementState lastMovementState = MovementState.IDLE; - private int overFlowEXP = 0; + public int overFlowEXP = 0; private int lastGuildToInvite; private int lastGroupToInvite; private boolean follow = false; @@ -137,12 +120,11 @@ public class PlayerCharacter extends AbstractCharacter { private int lastTargetID; private int hidden = 0; // current rank of hide/sneak/invis private int seeInvis = 0; // current rank of see invis - private float speedMod; + public float speedMod; private boolean teleportMode = false; // Teleport on MoveToPoint - private float dexPenalty; private long lastPlayerAttackTime = 0; - private long lastUpdateTime = System.currentTimeMillis(); - private long lastStamUpdateTime = System.currentTimeMillis(); + public long lastUpdateTime = System.currentTimeMillis(); + public long lastStamUpdateTime = System.currentTimeMillis(); private boolean safeZone = false; private int bindBuildingID; @@ -150,19 +132,16 @@ public class PlayerCharacter extends AbstractCharacter { DataWarehouse based kill/death tracking. These sets contain the last 10 UUID's */ - private boolean noTeleScreen = false; private int lastRealmID = -2; private int subRaceID = 0; - private boolean hasAnniversery = false; private DeferredPowerJob weaponPower; private NPC lastNPCDialog; private Mob pet; //Used for skill/Power calculation optimization - private CharacterTitle title = CharacterTitle.NONE; - private boolean asciiLastName = true; - private int spamCount = 0; - private boolean initialized = false; - private boolean enteredWorld = false; + public CharacterTitle title = CharacterTitle.NONE; + public boolean asciiLastName = true; + public boolean initialized = false; + public boolean enteredWorld = false; private boolean canBreathe = true; private String hash; private ArrayList guildHistory = new ArrayList<>(); @@ -170,10 +149,9 @@ public class PlayerCharacter extends AbstractCharacter { private boolean wasTripped50 = false; private boolean wasTripped25 = false; private float characterHeight = 0; - private boolean lastSwimming = false; - private boolean isTeleporting = false; - private boolean dirtyLoad = true; - private final ReadWriteLock dirtyLock = new ReentrantReadWriteLock(true); + public boolean lastSwimming = false; + public boolean dirtyLoad = true; + public final ReadWriteLock dirtyLock = new ReentrantReadWriteLock(true); public float ZergMultiplier = 1.0f; @@ -247,1451 +225,32 @@ public class PlayerCharacter extends AbstractCharacter { this.guildStatus = new AtomicInteger(0); Guild guild = Guild.getGuild(this.getGuildUUID()); - if (guild != null && guild.isGuildLeader(this.getObjectUUID())) - this.setGuildLeader(true); - else - this.setGuildLeader(false); - - this.hasAnniversery = rs.getBoolean("anniversery"); - - this.setInnerCouncil(rs.getBoolean("guild_isInnerCouncil")); - this.setFullMember(rs.getBoolean("guild_isFullMember")); - this.setTaxCollector(rs.getBoolean("guild_isTaxCollector")); - this.setRecruiter(rs.getBoolean("guild_isRecruiter")); - this.setGuildTitle(rs.getInt("guild_title")); - - if (this.account != null) - this.ignoredPlayerIDs = DbManager.PlayerCharacterQueries.GET_IGNORE_LIST(this.account.getObjectUUID(), false); - - this.strMod.set(rs.getShort("char_strMod")); - this.dexMod.set(rs.getShort("char_dexMod")); - this.conMod.set(rs.getShort("char_conMod")); - this.intMod.set(rs.getShort("char_intMod")); - this.spiMod.set(rs.getShort("char_spiMod")); - - this.bindBuildingID = rs.getInt("char_bindBuilding"); - - this.hash = rs.getString("hash"); - - - // For debugging skills - // CharacterSkill.printSkills(this); - } - - public static Building getUpdatedBindBuilding(PlayerCharacter player) { - Building returnBuilding = null; - - //update bindBuilding based on Guild or nation TOL; - - if (player.getBindBuildingID() == 0) { - - returnBuilding = PlayerCharacter.getBindBuildingForGuild(player); - - if (returnBuilding != null) - player.setBindBuildingID(returnBuilding.getObjectUUID()); - return returnBuilding; - } - returnBuilding = BuildingManager.getBuildingFromCache(player.getBindBuildingID()); - - if (returnBuilding == null) { - returnBuilding = PlayerCharacter.getBindBuildingForGuild(player); - - if (returnBuilding != null) - player.setBindBuildingID(returnBuilding.getObjectUUID()); - } - return returnBuilding; - } - - public static Building getBindBuildingForGuild(PlayerCharacter player) { - - Building returnBuilding; - - if (player.getGuild() == null || player.getGuild().isEmptyGuild()) - return null; - - if (player.getGuild().getOwnedCity() == null) { - - if (player.getGuild().getNation().getOwnedCity() == null) - return null; - - if (player.getGuild().getNation().getOwnedCity().getTOL() == null) - return null; - - returnBuilding = player.getGuild().getNation().getOwnedCity().getTOL(); - player.setBindBuildingID(returnBuilding.getObjectUUID()); - return returnBuilding; - } - - if (player.getGuild().getOwnedCity().getTOL() == null) - return null; - - returnBuilding = player.getGuild().getOwnedCity().getTOL(); - return returnBuilding; - } - - public static void __serializeForClientMsg(PlayerCharacter playerCharacter, ByteBufferWriter writer) throws SerializationException { - serializeForClientCommon(playerCharacter, writer, true, false, false, false); - } - - public static void serializeForClientMsgLogin(PlayerCharacter playerCharacter, ByteBufferWriter writer) throws SerializationException { - serializeForClientCommon(playerCharacter, writer, true, false, false, false); - } - - public static void serializeForClientMsgCommit(PlayerCharacter playerCharacter, ByteBufferWriter writer) throws SerializationException { - serializeForClientCommon(playerCharacter, writer, true, true, false, false); - } - - public static void serializeForClientMsgFull(PlayerCharacter playerCharacter, ByteBufferWriter writer) throws SerializationException { - serializeForClientCommon(playerCharacter, writer, false, false, false, false); - } - - public static void serializeForClientMsgOtherPlayer(PlayerCharacter playerCharacter, ByteBufferWriter writer) throws SerializationException { - serializeForClientCommon(playerCharacter, writer, false, false, true, false); - } - - public static void serializePlayerForClientMsgOtherPlayer(PlayerCharacter playerCharacter, ByteBufferWriter writer, boolean hideAsciiLastName) throws SerializationException { - serializeForClientCommon(playerCharacter, writer, false, false, true, hideAsciiLastName); - } - - // TODO what is a Fresh Char? - private static void serializeForClientCommon(PlayerCharacter playerCharacter, ByteBufferWriter writer, boolean loginData, boolean freshChar, boolean otherPlayer, boolean hideAsciiLastName) - throws SerializationException { - - /* - * RUNES - */ - // Handle Applied Runes - writer.putInt(0); // Pad - writer.putInt(0); // Pad - - // Put number of runes - //We need to send all runes to everyone, otherwise playerCharacter will cause major issues - if (playerCharacter.promotionClass != null) - writer.putInt(playerCharacter.runes.size() + 3); - else - writer.putInt(playerCharacter.runes.size() + 2); - - // Cant forget that Race and baseClass are technically Runes :0 - if (playerCharacter.subRaceID != 0) { - writer.putInt(1); // For Race - writer.putInt(0); // Pad - writer.putInt(playerCharacter.subRaceID); - - writer.putInt(Enum.GameObjectType.Race.ordinal()); - writer.putInt(playerCharacter.subRaceID); - } else - playerCharacter.race.serializeForClientMsg(writer); - if (playerCharacter.promotionClass != null) { - BaseClass.serializeForClientMsg(playerCharacter.baseClass, writer, 2); - PromotionClass.serializeForClientMsg(playerCharacter.promotionClass, writer); - } else - BaseClass.serializeForClientMsg(playerCharacter.baseClass, writer, 3); - - // Put runes. - - for (CharacterRune rb : playerCharacter.runes) { - CharacterRune.serializeForClientMsg(rb, writer); - } - - /* - * STATS - */ - // Number of Stats to follow - writer.putInt(5); - - writer.putInt(MBServerStatics.STAT_STR_ID); // Strength ID - writer.putInt(freshChar ? 0 : playerCharacter.getStrMod()); - - writer.putInt(MBServerStatics.STAT_SPI_ID); // Spirit ID - writer.putInt(freshChar ? 0 : playerCharacter.getSpiMod()); - - writer.putInt(MBServerStatics.STAT_CON_ID); // Constitution ID - writer.putInt(freshChar ? 0 : playerCharacter.getConMod()); - - writer.putInt(MBServerStatics.STAT_DEX_ID); // Dexterity ID - writer.putInt(freshChar ? 0 : playerCharacter.getDexMod()); - - writer.putInt(MBServerStatics.STAT_INT_ID); // Intelligence ID - writer.putInt(freshChar ? 0 : playerCharacter.getIntMod()); - - // Handle Info - playerCharacter.title._serializeFirstName(writer, playerCharacter.firstName); - playerCharacter.title._serializeLastName(writer, playerCharacter.lastName, hideAsciiLastName, playerCharacter.asciiLastName); - - // Unknown - writer.putInt(0); - - writer.putString(ConfigManager.MB_WORLD_NAME.getValue()); - writer.putInt(WorldServer.worldMapID); - - writer.put((byte) 1); // End Datablock byte - writer.putInt(0); // Unsure, Pad? - writer.putInt(playerCharacter.getObjectType().ordinal()); - writer.putInt(playerCharacter.getObjectUUID()); - - // Perhaps playerCharacter is loc and the next 3 are Facing dir? - writer.putFloat(1); // Unknown - writer.putFloat(playerCharacter.race.getRaceType().getScaleHeight()); // Unknown - writer.putFloat(1); // Unknown - - writer.putVector3f(playerCharacter.getLoc()); - writer.putFloat(playerCharacter.faceDir.getRotation()); // Rotation, direction - - // facing - - // Running trains. - - if (otherPlayer) { - CharacterSkill runSkill = playerCharacter.skills.get("Running"); - if (runSkill == null) - // Logger.log.log( - // LogEventType.WARNING, - // "Failed to find the 'Running Skill' when serializing PlayerCharacter '" - // + playerCharacter.getCombinedName() + "'"); - // TODO put int=0 for now. - writer.putInt(0); - else - writer.putInt(runSkill.getNumTrains()); - } else - writer.putInt(0); - - - ArrayList equipped = playerCharacter.charItemManager.getEquippedList(); - - writer.putInt(equipped.size()); - for (Item item : equipped) { - Item._serializeForClientMsg(item, writer); - } - writer.putInt(playerCharacter.getRank()); - - writer.putInt(playerCharacter.getLevel()); - if (loginData) - writer.putInt(5); - else - writer.putInt(playerCharacter.getIsSittingAsInt()); // 5 - writer.putInt(playerCharacter.getIsWalkingAsInt()); // 1 - writer.putInt(playerCharacter.getIsCombatAsInt()); // 1 - writer.putInt(playerCharacter.getIsFlightAsInt()); // 2 or 3 - - writer.putInt(playerCharacter.getIsLfGroupAsInt()); // 1 - - // if (loginData) - // writer.putInt(0); - // else - writer.putInt(playerCharacter.getHeadlightsAsInt()); - - - if (playerCharacter.region != null && !loginData) { - Building building = Regions.GetBuildingForRegion(playerCharacter.region); - - if (building == null) { - writer.putInt(0); - writer.putInt(0); - } else { - writer.putInt(GameObjectType.Building.ordinal()); - writer.putInt(building.getObjectUUID()); - } - - } else { - writer.putInt(0); - writer.putInt(0); - } - - - writer.put((byte) 0); - writer.put((byte) 0); - writer.put((byte) 0); - writer.putInt(0); - writer.put((byte) 0); - writer.put((byte) 0); - writer.put((byte) 0); - -// writer.putInt(0); -// writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - - if (!playerCharacter.isAlive() && otherPlayer) { - writer.putInt(0); - writer.putInt(0); - } - - - //TODO FIGURE OUT THE REAL SEARLIZATION FOR NEXT 2 SHORTS? - writer.putInt(playerCharacter.skinColor); // Skin Color - writer.putFloat(20); - writer.put((byte) 0); //Unknown - - //unknown object - writer.putInt(0); - writer.putInt(0); - - //unknown type - writer.putInt(0); - //0x4080 should be the next short here, instead it wraps 0's down their in for loops.. seriously.. who wrote playerCharacter shit. - // playerCharacter aint right! - // ByteBufferUtils.putString(writer, playerCharacter.guild.getName()); - // writer.putInt(playerCharacter.getGuild().getUUID()); - // ByteBufferUtils.putString(writer, playerCharacter.guild.getNation().getName()); - // writer.putInt(playerCharacter.getGuild().getNation().getUUID()); - Guild.serializeForClientMsg(playerCharacter.getGuild(), writer, playerCharacter, false); - - //Send Tokens for race/class/promotion (disciplines?) - if (playerCharacter.promotionClass != null) - writer.putInt(3); - else - writer.putInt(2); - writer.putInt(playerCharacter.race.getToken()); - writer.putInt(playerCharacter.baseClass.getToken()); - if (playerCharacter.promotionClass != null) - writer.putInt(playerCharacter.promotionClass.getToken()); - // writer.putInt(2); // Unknown Counter - // writer.putInt(0x04C1BE88); // Unknown - // writer.putInt(0x0F651512); // Unknown - - writer.putFloat(playerCharacter.altitude); // altitude? - writer.putFloat(playerCharacter.altitude); // altitude? - writer.put((byte) 0); // End Datablock byte - - writer.putFloat(playerCharacter.healthMax); - writer.putFloat(playerCharacter.health.get()); - - writer.put((byte) 0); // End Datablock byte - //size - - - if (loginData) { - writer.putInt(0); - } else { - int indexPosition = writer.position(); - writer.putInt(0); //placeholder for item cnt - int total = 0; - // Logger.info("",""+ playerCharacter.getEffects().size()); - for (Effect eff : playerCharacter.getEffects().values()) { - if (eff.getPower() == null && otherPlayer) - continue; - if (eff.getPower() != null && eff.getPower().token == 429506619) // Oblivion's Caress - continue; - if (!eff.serializeForLoad(writer)) - continue; - ++total; - - } - - writer.putIntAt(total, indexPosition); - } - - if (otherPlayer) { - writer.put((byte) 0); // End Datablock Byte - return; - - } - - //made up for sendalleffects - //writer.putInt(0); // Pad - //writer.put((byte) 0); // End Datablock byte - writer.putInt(playerCharacter.getUnusedStatPoints()); - writer.putInt(playerCharacter.getLevel()); - writer.putInt(playerCharacter.getExp() + playerCharacter.overFlowEXP); - writer.putFloat(playerCharacter.manaMax); - writer.putFloat(playerCharacter.mana.get()); - writer.putFloat(playerCharacter.staminaMax); - writer.putFloat(playerCharacter.stamina.get()); - writer.putInt(playerCharacter.getAtrHandOne()); - writer.putInt(playerCharacter.getAtrHandTwo()); - writer.putInt(playerCharacter.getDefenseRating()); - - if (MBServerStatics.POWERS_DEBUG) //debug mode, grant lots of trains - writer.putInt(1000); - else - writer.putInt(playerCharacter.trainsAvailable.get()); - - /* - * Skills - */ - if (loginData) - writer.putInt(0); // Skip skills - else { - writer.putInt(playerCharacter.skills.size()); - Iterator it = playerCharacter.skills.keySet().iterator(); - while (it.hasNext()) { - String name = it.next(); - CharacterSkill.serializeForClientMsg(playerCharacter.skills.get(name), writer); - } - } - - /* - * Powers - */ - if (loginData) - writer.putInt(0); // Skip Powers - else if (MBServerStatics.POWERS_DEBUG) //debug mode, grant all powers - PowersManager.testPowers(writer); - else { - writer.putInt(playerCharacter.powers.size()); - for (CharacterPower sp : playerCharacter.powers.values()) { - CharacterPower.serializeForClientMsg(sp, writer); - } - } - - /* - * Inventory - */ - if (loginData) { - writer.putInt(0); // Skip Inventory - writer.putInt(playerCharacter.getInventoryCapacity()); // Inventory Capacity - - } else { - ArrayList inv = playerCharacter.charItemManager.getInventory(true); - Item.putList(writer, inv, false, playerCharacter.getObjectUUID()); - writer.putInt(playerCharacter.getInventoryCapacityRemaining()); - } - - /* - * Bank - */ - if (loginData) { - writer.putInt(0); // Skip Bank - writer.putInt(AbstractCharacter.getBankCapacity()); // Bank Capacity - - } else { - ArrayList bank = playerCharacter.charItemManager.getBank(); - - Item.putList(writer, bank, false, playerCharacter.getObjectUUID()); - writer.putInt(playerCharacter.getBankCapacityRemaining()); - } - //load player friends. - if (loginData) - writer.putInt(0); - else { - HashSet friendMap = PlayerFriends.PlayerFriendsMap.get(playerCharacter.getObjectUUID()); - if (friendMap == null) - writer.putInt(0); - else { - writer.putInt(friendMap.size()); - for (int friendID : friendMap) { - PlayerCharacter friend = PlayerCharacter.getFromCache(friendID); - //shouldn't get here, but if null serialize blank friend. - if (friend == null) { - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - } else { - writer.putInt(friend.getObjectType().ordinal()); - writer.putInt(friend.getObjectUUID()); - writer.putString(friend.getName()); - boolean online = SessionManager.getPlayerCharacterByID(friend.getObjectUUID()) != null ? true : false; - writer.putInt(online ? 0 : 1); - writer.putInt(friend.friendStatus.ordinal()); - } - - } - } - } - - - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - writer.putInt(0); - - writer.putShort((short) 0); - writer.put((byte) 0); - // playerCharacter is for send self in enter world (full character) - if (!loginData && !freshChar) { - int size = playerCharacter.getRecycleTimers().size(); - writer.putInt(size); - if (size > 0) - for (int token : playerCharacter.getRecycleTimers().keySet()) { - - JobContainer frtj = playerCharacter.getRecycleTimers().get(token); - long timeLeft = frtj.timeOfExection() - System.currentTimeMillis(); - writer.putInt(token); - writer.putInt((int) timeLeft / 1000); - } - DateTime enterWorld = new DateTime(playerCharacter.timestamps.get("EnterWorld")); - writer.putDateTime(enterWorld); - - writer.putInt(0x49EF1E98); //DUnno what playerCharacter is. - writer.putFloat(DateTime.now().hourOfDay().get()); //daylight in float. - writer.putFloat(6); //interval of light to change per game hour //float - //writer.putInt(1637194901); //playerCharacter is actually an opcode taht is in recordings, no clue what it is, dumped it and it changes nothing - } else { - writer.put((byte) 0); //added to compensate the cooldown check. - - //add server up or down - int serverUp = LoginServer.worldServerRunning ? 1 : 0; - - if (playerCharacter.account == null) - serverUp = 0; - - if ((playerCharacter.account.status.equals(AccountStatus.ADMIN) == false) && - (playerCharacter.account.status.equals(WorldServer.worldAccessLevel) == false)) - serverUp = 0; - - writer.putInt(serverUp); - writer.putInt(0); // effects, not sure used by players - writer.put((byte) 0); // End Player Datablock - } - - } - - public static PlayerCharacter generatePCFromCommitNewCharacterMsg(Account a, CommitNewCharacterMsg msg, ClientConnection clientConnection) { - - String firstName = msg.getFirstName().trim(); - String lastName = msg.getLastName().trim(); - - if (firstName.length() < 3) { - LoginServerMsgHandler.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_FIRSTNAME_MUST_BE_LONGER, - clientConnection); - return null; - } - - // Ensure names are below required length - if (firstName.length() > 15 || lastName.length() > 15) { - LoginServerMsgHandler.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_FIRSTANDLAST_MUST_BE_SHORTER, - clientConnection); - return null; - } - - // Check if firstname is valid - if (MiscUtils.checkIfFirstNameInvalid(firstName)) { - LoginServerMsgHandler.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_PLEASE_CHOOSE_ANOTHER_FIRSTNAME, - clientConnection); - return null; - } - - // Check if last name is valid - if (MiscUtils.checkIfLastNameInvalid(lastName)) { - LoginServerMsgHandler.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_LASTNAME_UNAVAILABLE, - clientConnection); - return null; - } - - // Verify Race - int raceID = msg.getRace(); - - if(raceID == 0) - raceID = 1999; - - Race race = Race.getRace(raceID); - - if (race == null) { - Logger.info("Invalid RaceID: " + raceID); - return null; - } - - // Verify BaseClass Object. - int baseClassID = msg.getBaseClass(); - BaseClass baseClass = DbManager.BaseClassQueries.GET_BASE_CLASS(baseClassID); - - if (baseClass == null) { - Logger.info("Invalid BaseClasID: " + baseClassID); - return null; - } - - // Verify Race/baseClass combo. - boolean valid = false; - - for (BaseClass bc : race.getValidBaseClasses()) { - - if (bc.getObjectUUID() == baseClassID) { - valid = true; - break; - } - } - - if (!valid) { - Logger.info("Invalid BaseClass/Race Combo"); - return null; - } - - // Verify HairStyle/BeardStyle/SkinColor/HairColor/BeardColor - int hairStyleID = msg.getHairStyle(); - int beardStyleID = msg.getBeardStyle(); - int skinColorID = msg.getSkinColor(); - int hairColorID = msg.getHairColor(); - int beardColorID = msg.getBeardColor(); - - if(raceID != 1999) { - if (!race.isValidHairStyle(hairStyleID)) { - Logger.info("Invalid HairStyleID: " + hairStyleID + " for race: " + race.getName()); - return null; - } - - if (!race.isValidSkinColor(skinColorID)) { - Logger.info("Invalid skinColorID: " + skinColorID + " for race: " + race.getName()); - return null; - } - - if (!race.isValidHairColor(hairColorID)) { - Logger.info("Invalid hairColorID: " + hairColorID + " for race: " + race.getName()); - return null; - } - - if (!race.isValidBeardColor(beardColorID)) { - Logger.info("Invalid beardColorID: " + beardColorID + " for race: " + race.getName()); - return null; - } - } - // Get stat modifiers - int strMod = msg.getStrengthMod(); - int dexMod = msg.getDexterityMod(); - int conMod = msg.getConstitutionMod(); - int intMod = msg.getIntelligenceMod(); - int spiMod = msg.getSpiritMod(); - - - if (intMod < -5 || dexMod < -5 || conMod < -5 || strMod < -5 || spiMod < -5) { - Logger.error("NEGATIVE STAT CHEAT ATTEMPTED! ACCOUNT: " + a.getUname() + "(" + a.getObjectUUID() + ") IP ADDRESS: " + clientConnection.getClientIpAddress()); - return null; - } - - // calculate current stats: - short strCur = (short) (race.getStrStart() + baseClass.getStrMod() + strMod); - short dexCur = (short) (race.getDexStart() + baseClass.getDexMod() + dexMod); - short conCur = (short) (race.getConStart() + baseClass.getConMod() + conMod); - short intCur = (short) (race.getIntStart() + baseClass.getIntMod() + intMod); - short spiCur = (short) (race.getSpiStart() + baseClass.getSpiMod() + spiMod); - - // calculate max stats: - short strMax = race.getStrMax(); - short dexMax = race.getDexMax(); - short conMax = race.getConMax(); - short intMax = race.getIntMax(); - short spiMax = race.getSpiMax(); - - // Verify not too many runes applied - int numRunes = msg.getNumRunes(); - - if (numRunes > 16) { - Logger.info("Too many Runes applied"); - return null; - } - - // Get Runes - // ArrayList characterRunesUsed = new ArrayList(); - // ArrayList subtypesUsed = new ArrayList(); - int remainingPoints = race.getStartingPoints() - strMod - dexMod - conMod - intMod - spiMod; - - int[] characterRunes = msg.getRunes(); - - HashSet usedRunesSubType = new HashSet<>(); - HashSet usedRunes = new HashSet<>(); - - // So that all the penalties can be added at the end. - ConcurrentHashMap penalties = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - - penalties.put("StrCur", 0); - penalties.put("StrMax", 0); - penalties.put("DexCur", 0); - penalties.put("DexMax", 0); - penalties.put("ConCur", 0); - penalties.put("ConMax", 0); - penalties.put("IntCur", 0); - penalties.put("IntMax", 0); - penalties.put("SpiCur", 0); - penalties.put("SpiMax", 0); - - PriorityQueue> orderedRunes = new PriorityQueue<>(14, - new Comparator>() { - - @Override - public int compare(Entry o1, Entry o2) { - return o1.getKey() - o2.getKey(); - } - }); - - // Figure out which Runes we are adding. - for (int i : characterRunes) { - // Zero skip - if (i == 0) - continue; - - // Skip the Race and BaseClass runes... already dealt with. - if (i == raceID || i == baseClassID) - continue; - - RuneBase runeBase = RuneBase.getRuneBase(i); - - // Null check - if (runeBase == null) { - Logger.info("GOM returned NULL RuneBase"); - return null; - } - - // Validate Rune against Race - if(raceID != 1999) { - if (!race.isAllowedRune(runeBase)) { - Logger.info("Trait Not valid for Race"); - return null; - } - } - // Validate BaseClass against Race - if (!baseClass.isAllowedRune(runeBase)) { - Logger.info("Trait Not valid for BaseClass"); - return null; - } - - int previous_size = usedRunes.size(); - int previous_subtype = usedRunesSubType.size(); - - usedRunes.add(runeBase); - usedRunesSubType.add(runeBase.getSubtype()); - - // Duplicate Rune check - if (usedRunes.size() <= previous_size) { - Logger.info("Duplicate RuneBase"); - return null; - } - - // Duplicate Subtype check - if (runeBase.getSubtype() != 0 && usedRunesSubType.size() <= previous_subtype) { - Logger.info("Duplicate RuneBase Subtype"); - return null; - } - - int maxValue = 0; - - // Every attempt is made to load MIN_NEEDED_ATTRIBUTES first. - - if (runeBase.getAttrs() != null) - for (RuneBaseAttribute rba : runeBase.getAttrs()) { - if (rba.getAttributeID() == MBServerStatics.RUNE_STR_MIN_NEEDED_ATTRIBUTE_ID - || rba.getAttributeID() == MBServerStatics.RUNE_DEX_MIN_NEEDED_ATTRIBUTE_ID - || rba.getAttributeID() == MBServerStatics.RUNE_CON_MIN_NEEDED_ATTRIBUTE_ID - || rba.getAttributeID() == MBServerStatics.RUNE_INT_MIN_NEEDED_ATTRIBUTE_ID - || rba.getAttributeID() == MBServerStatics.RUNE_SPI_MIN_NEEDED_ATTRIBUTE_ID) { - maxValue = rba.getModValue(); - if (runeBase.getName().equals("Giant's Blood")) - maxValue = 45; // Take care of the Giant's Blood special - // case. - break; - } - } - - orderedRunes.add(new AbstractMap.SimpleEntry<>(maxValue, runeBase)); - } - - while (orderedRunes.size() > 0) { - RuneBase rb = orderedRunes.remove().getValue(); - ArrayList attrs = rb.getAttrs(); - - if (attrs != null) - for (RuneBaseAttribute abr : attrs) { - - int attrID = abr.getAttributeID(); - int value = abr.getModValue(); - - switch (attrID) { - case MBServerStatics.RUNE_COST_ATTRIBUTE_ID: - - Logger.info("Bought " + rb.getName() + " for " + value + " points. " - + (remainingPoints - value) + " left."); - - if ((remainingPoints - value) >= 0) { - remainingPoints -= value; - continue; - } - Logger.info("Not enough points left"); - return null; - case MBServerStatics.RUNE_STR_MIN_NEEDED_ATTRIBUTE_ID: - - if (strCur >= value) - continue; - - Logger.info("STR fails to meet Rune Minimum --> " + rb.getName()); - return null; - case MBServerStatics.RUNE_DEX_MIN_NEEDED_ATTRIBUTE_ID: - - if (dexCur >= value) - continue; - - Logger.info("DEX fails to meet Rune Minimum --> " + rb.getName()); - return null; - case MBServerStatics.RUNE_CON_MIN_NEEDED_ATTRIBUTE_ID: - - if (conCur >= value) - continue; - - Logger.info("CON fails to meet Rune Minimum --> " + rb.getName()); - return null; - case MBServerStatics.RUNE_INT_MIN_NEEDED_ATTRIBUTE_ID: - - if (intCur >= value) - continue; - - Logger.info("INT fails to meet Rune Minimum --> " + rb.getName()); - return null; - case MBServerStatics.RUNE_SPI_MIN_NEEDED_ATTRIBUTE_ID: - - if (spiCur >= value) - continue; - - Logger.info("SPI fails to meet Rune Minimum --> " + rb.getName()); - return null; - case MBServerStatics.RUNE_STR_ATTRIBUTE_ID: - - if (value < 0) - penalties.put("StrCur", (penalties.get("StrCur") + value)); - else - strCur += value; - continue; - - case MBServerStatics.RUNE_DEX_ATTRIBUTE_ID: - if (value < 0) - penalties.put("DexCur", (penalties.get("DexCur") + value)); - else - dexCur += value; - continue; - case MBServerStatics.RUNE_CON_ATTRIBUTE_ID: - if (value < 0) - penalties.put("ConCur", (penalties.get("ConCur") + value)); - else - conCur += value; - continue; - case MBServerStatics.RUNE_INT_ATTRIBUTE_ID: - if (value < 0) - penalties.put("IntCur", (penalties.get("IntCur") + value)); - else - intCur += value; - continue; - case MBServerStatics.RUNE_SPI_ATTRIBUTE_ID: - if (value < 0) - penalties.put("SpiCur", (penalties.get("SpiCur") + value)); - else - spiCur += value; - continue; - case MBServerStatics.RUNE_STR_MAX_ATTRIBUTE_ID: - if (value < 0) - penalties.put("StrMax", (penalties.get("StrMax") + value)); - else - strMax += value; - continue; - case MBServerStatics.RUNE_DEX_MAX_ATTRIBUTE_ID: - if (value < 0) - penalties.put("DexMax", (penalties.get("DexMax") + value)); - else - dexMax += value; - continue; - case MBServerStatics.RUNE_CON_MAX_ATTRIBUTE_ID: - if (value < 0) - penalties.put("ConMax", (penalties.get("ConMax") + value)); - else - conMax += value; - continue; - case MBServerStatics.RUNE_INT_MAX_ATTRIBUTE_ID: - if (value < 0) - penalties.put("IntMax", (penalties.get("IntMax") + value)); - else - intMax += value; - continue; - case MBServerStatics.RUNE_SPI_MAX_ATTRIBUTE_ID: - if (value < 0) - penalties.put("SpiMax", (penalties.get("SpiMax") + value)); - else - spiMax += value; - continue; - - default: - Logger.info("Unknown ATTRIBUTE_ID while checking RuneBaseAttributes: " + attrID); - return null; - } - } - } - - // Add in all of the penalties. - strCur += penalties.get("StrCur"); - strMax += penalties.get("StrMax"); - dexCur += penalties.get("DexCur"); - dexMax += penalties.get("DexMax"); - conCur += penalties.get("ConCur"); - conMax += penalties.get("ConMax"); - intCur += penalties.get("IntCur"); - intMax += penalties.get("IntMax"); - spiCur += penalties.get("SpiCur"); - spiMax += penalties.get("SpiMax"); - - int kitID = msg.getKit(); - - // get the correctKit - int raceClassID; - if(raceID != 1999){ - raceClassID = Kit.GetKitIDByRaceClass(raceID, baseClassID); - }else{ - raceClassID = Kit.GetKitIDByRaceClass(2011, baseClassID); - } - ArrayList allKits = Kit.RaceClassIDMap.get(raceClassID); - - - Kit kit = null; - - for (Kit k : allKits) { - if (k.getKitNumber() == kitID) { - kit = k; - break; - } - } - - if (kit == null) { - Logger.info("Unable to find matching kitID: " + kitID); - return null; - } - - byte runningTrains = 0; - PlayerCharacter playerCharacter; - - //Synchronized block to allow exclusive access when confirming - //uniqueness of FirstName and subsequently saving the new record - //to the database with that FirstName - synchronized (FirstNameLock) { - // Test if FirstName already exists. - // This must be the very last check before calling the - // DB to create the character record - if (DbManager.PlayerCharacterQueries.IS_CHARACTER_NAME_UNIQUE(firstName) == false) { - LoginServerMsgHandler.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_FIRSTNAME_UNAVAILABLE, - clientConnection); - return null; - } - if(raceID == 1999){ - hairStyleID = 0; - beardStyleID = 0; - skinColorID = 0; - hairColorID = 0; - beardColorID = 0; - } - - // Make PC - PlayerCharacter pcWithoutID = new PlayerCharacter(firstName, lastName, (short) strMod, (short) dexMod, (short) conMod, - (short) intMod, (short) spiMod, Guild.getErrantGuild(), runningTrains, a, race, baseClass, (byte) skinColorID, (byte) hairColorID, - (byte) beardColorID, (byte) beardStyleID, (byte) hairStyleID); - - try { - playerCharacter = DbManager.PlayerCharacterQueries.ADD_PLAYER_CHARACTER(pcWithoutID); - } catch (Exception e) { - Logger.error("generatePCFromCommitNewCharacterMsg", "An error occurred while saving new PlayerCharacter to DB", e); - return null; - } - - if (playerCharacter == null) { - Logger.info("GOM Failed to create PlayerCharacter"); - return null; - } - - } // END synchronized(FirstNameLock) - - // Add creation runes - for (RuneBase rb : usedRunes) { - CharacterRune runeWithoutID = new CharacterRune(rb, playerCharacter.getObjectUUID()); - CharacterRune characterRune; - try { - characterRune = DbManager.CharacterRuneQueries.ADD_CHARACTER_RUNE(runeWithoutID); - } catch (Exception e) { - characterRune = null; - } - - if (characterRune == null) { - playerCharacter.deactivateCharacter(); - Logger.info("GOM Failed to create CharacterRune"); - return null; - } - - playerCharacter.addRune(characterRune); - } - - if (hairStyleID != 0) { - // Create Hair - Item tempHair = new Item(ItemBase.getItemBase(hairStyleID), playerCharacter.getObjectUUID(), OwnerType.PlayerCharacter, - (byte) 0, (byte) 0, (short) 1, (short) 1, false, false, ItemContainerType.EQUIPPED, - (byte) MBServerStatics.SLOT_HAIRSTYLE, new ArrayList<>(), ""); - - Item hair; - - try { - hair = DbManager.ItemQueries.ADD_ITEM(tempHair); - } catch (Exception e) { - hair = null; - } - - if (hair == null) { - playerCharacter.deactivateCharacter(); - Logger.info("GameObjectManager failed to create Hair:" + hairStyleID + " in Slot:" - + MBServerStatics.SLOT_HAIRSTYLE); - return null; - } - } - - if (beardStyleID != 0) { - // Create Beard - Item tempBeard = new Item(ItemBase.getItemBase(beardStyleID), playerCharacter.getObjectUUID(), OwnerType.PlayerCharacter, - (byte) 0, (byte) 0, (short) 1, (short) 1, false, false, ItemContainerType.EQUIPPED, - (byte) MBServerStatics.SLOT_BEARDSTYLE, new ArrayList<>(), ""); - Item beard; - try { - beard = DbManager.ItemQueries.ADD_ITEM(tempBeard); - } catch (Exception e) { - beard = null; - } - - if (beard == null) { - playerCharacter.deactivateCharacter(); - Logger.info("GameObjectManager failed to create Beard:" + beardStyleID + " in Slot:" - + MBServerStatics.SLOT_BEARDSTYLE); - return null; - } - } - // Create items from Kit and equip on character. - try { - kit.equipPCwithKit(playerCharacter); - } catch (Exception e) { - Logger.info("Unable to find KIT ID for Race: " + raceID + "||" + "Class:" + baseClassID); - playerCharacter.deactivateCharacter(); - return null; - } - - // Get any new skills that belong to the player - playerCharacter.calculateSkills(); - - a.setLastCharacter(playerCharacter.getObjectUUID()); - playerCharacter.charItemManager.load(); - - playerCharacter.activateCharacter(); - - return playerCharacter; - } - - public static boolean isIgnoreListFull() { - return false; //Why were we setting a limit on ignores? - - //return (ignoredPlayerIDs.size() >= MBServerStatics.IGNORE_LIST_MAX); - } - - public static boolean isIgnorable() { - return true; - // // if (account == null) return false; - // if (account.getAccessLevel() > 0) { - // return false; - // } - // return true; - } - - /** - * @ Initialize player upon creation - */ - public static void initializePlayer(PlayerCharacter player) { - - if (player.initialized) - return; - // Logger.info("", " Initializing " + player.getCombinedName()); - player.skills = DbManager.CharacterSkillQueries.GET_SKILLS_FOR_CHARACTER(player); - player.powers = player.initializePowers(); - - - if (ConfigManager.serverType.equals(ServerType.WORLDSERVER)) - player.setLoc(player.getBindLoc()); - player.endLoc = Vector3fImmutable.ZERO; - - //get level based on experience - player.level = (short) Experience.getLevel(player.exp); - - player.setHealth(999999f); - player.mana.set(999999f); - player.stamina.set(999999f); - player.bonuses = new PlayerBonuses(player); - PlayerBonuses.InitializeBonuses(player); - player.resists = new Resists(player); - player.charItemManager.load(); - - if (ConfigManager.serverType.equals(ServerType.WORLDSERVER)) { - - //CharacterSkill.updateAllBaseAmounts(this); - CharacterPower.grantTrains(player); - - // calculate skills. Make sure none are missing. - AbstractCharacter.runBonusesOnLoad(player); - - PlayerCharacter.InitializeSkillsOnLoad(player); - - //apply all bonuses - player.recalculatePlayerStats(true); - player.trainsAvailable.set(CharacterSkill.getTrainsAvailable(player)); - - if (player.trainsAvailable.get() < 0) - player.recalculateTrains(); - - //this.resists.calculateResists(this); - player.newChar = true; - - //check current guild valid for player - player.checkGuildStatus(); - - player.setHealth(player.getHealthMax()); - player.mana.set(player.manaMax); - player.stamina.set(player.staminaMax); - } else - player.setBindLoc(Vector3fImmutable.ZERO); - - player.initialized = true; - - String lastAscii = player.lastName.replaceAll("[^\\p{ASCII}]", ""); - player.asciiLastName = lastAscii.equals(player.lastName); - } - - public static void recalculatePlayerStatsOnLoad(PlayerCharacter pc) { - - //calculate base stats - pc.calculateBaseStats(); - - //calculate base skills - CharacterSkill.updateAllBaseAmounts(pc); - pc.calculateModifiedStats(); - - //calculate modified skills - CharacterSkill.updateAllModifiedAmounts(pc); - - - //calculate modified stats - - - //calculate ATR, damage and defense - pc.calculateAtrDefenseDamage(); - - //calculate movement bonus - pc.calculateSpeedMod(); - - // recalculate Max Health/Mana/Stamina - pc.calculateMaxHealthManaStamina(); - - // recalculate Resists - Resists.calculateResists(pc); - - } - - public static boolean hideNonAscii() { - - return false; - } - - public static float getDexPenalty(Item armor) { - if (armor == null) - return 0f; - ItemBase ab = armor.getItemBase(); - if (ab == null) - return 0f; - return ab.getDexPenalty(); - } - - private static float getModifiedAmount(CharacterSkill skill) { - if (skill == null) - return 0f; - return skill.getModifiedAmount(); - } - - public static void InitializeSkillsOnLoad(PlayerCharacter pc) { - try { - { - - //see if any new skills or powers granted - CharacterSkill.calculateSkills(pc); - - // calculate granted Trains in powers. - CharacterPower.grantTrains(pc); - - //see if any new powers unlocked from previous check - CharacterPower.calculatePowers(pc); - } - } catch (Exception e) { - Logger.error(e.getMessage()); - } - - } - - public static String getFirstName(int tableId) { - - PlayerCharacter player; - - if (tableId == 0) - return ""; - - player = (PlayerCharacter) DbManager.getObject(GameObjectType.PlayerCharacter, tableId); - - return player.getFirstName(); - } - - public static PlayerCharacter getFromCache(int id) { - return (PlayerCharacter) DbManager.getFromCache(GameObjectType.PlayerCharacter, id); - } - - public static PlayerCharacter getByFirstName(String name) { - - PlayerCharacter returnPlayer = null; - for (AbstractGameObject ago : DbManager.getList(GameObjectType.PlayerCharacter)) { - PlayerCharacter cachePlayer = (PlayerCharacter) ago; - if (!name.equalsIgnoreCase(cachePlayer.getFirstName())) - continue; - if (cachePlayer.isDeleted()) - continue; - returnPlayer = cachePlayer; - break; - } - - return returnPlayer; - } - - public static PlayerCharacter getPlayerCharacter(int uuid) { - - PlayerCharacter outPlayer; - - outPlayer = DbManager.PlayerCharacterQueries.GET_PLAYER_CHARACTER(uuid); - - if (outPlayer != null) - return outPlayer; - - return (PlayerCharacter) DbManager.getFromCache(GameObjectType.PlayerCharacter, uuid); - } - - public static int GetPlayerRealmTitle(PlayerCharacter player) { - - if (player.getGuild().isEmptyGuild()) - return 0; - if (!player.getGuild().isGuildLeader(player.getObjectUUID())) - return 0; - if (player.getGuild().getOwnedCity() == null) - return 10; - if (player.getGuild().getOwnedCity().getRealm() == null) - return 10; - if (player.getGuild().getOwnedCity().getRealm().getRulingCity() == null) - return 10; - - if (player.getGuild().getOwnedCity().getRealm().getRulingCity().getObjectUUID() != player.getGuild().getOwnedCity().getObjectUUID()) - return 10; - int realmTitle = 1; - if (player.getGuild().getSubGuildList() == null || player.getGuild().getSubGuildList().isEmpty()) - return 11; - for (Guild subGuild : player.getGuild().getSubGuildList()) { - if (subGuild.getOwnedCity() == null) - continue; - if (subGuild.getOwnedCity().getRealm() == null) - continue; - if (subGuild.getOwnedCity().getRealm().getRulingCity() == null) - continue; - if (subGuild.getOwnedCity().getRealm().getRulingCity().getObjectUUID() != subGuild.getOwnedCity().getObjectUUID()) - continue; - realmTitle++; - } - - if (realmTitle < 3) - return 11; - else if (realmTitle < 5) - return 12; - else - return 13; - } - - public static void UpdateClientPlayerRank(PlayerCharacter pc) { - if (pc == null) - return; - boolean disable = true; - - if (disable) - return; - UpdateCharOrMobMessage ucm = new UpdateCharOrMobMessage(pc, 2, pc.getRank()); - DispatchMessage.sendToAllInRange(pc, ucm); - } - - public static void GroundPlayer(PlayerCharacter groundee) { - if (groundee.getDesiredAltitude() == 0 && groundee.getAltitude() == 0) - return; - groundee.setAltitude(groundee.getAltitude()); - groundee.setDesiredAltitude(0); - groundee.setTakeOffTime(System.currentTimeMillis()); - - ChangeAltitudeMsg msg = ChangeAltitudeMsg.GroundPlayerMsg(groundee); - // force a landing - DispatchMessage.dispatchMsgToInterestArea(groundee, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - - } - - public static boolean CanBreathe(PlayerCharacter breather) { - try { - if (breather.isFlying()) - return true; - Zone zone = ZoneManager.findSmallestZone(breather.getLoc()); - - if (zone.getSeaLevel() != 0) { - - float localAltitude = breather.getLoc().y; - - - if (localAltitude + breather.characterHeight < zone.getSeaLevel() - 2) - return false; - - if (breather.isMoving()) { - if (localAltitude + breather.characterHeight < zone.getSeaLevel()) - return false; - } - } else { - if (breather.getLoc().y + breather.characterHeight < -2) - return false; - - if (breather.isMoving()) { - if (breather.getLoc().y + breather.characterHeight < 0) - return false; - } - } - - - } catch (Exception e) { - Logger.info(breather.getName() + e); - } - - - return true; - } - - public static boolean enterWater(PlayerCharacter enterer) { - - try { - if (enterer.isFlying()) - return false; - - - Zone zone = ZoneManager.findSmallestZone(enterer.getLoc()); - - if (zone.getSeaLevel() != 0) { - - float localAltitude = enterer.getLoc().y + enterer.characterHeight; - - - if (localAltitude < zone.getSeaLevel()) - return true; - } else { - if (enterer.getLoc().y + enterer.characterHeight < 0) - return true; - } - } catch (Exception e) { - Logger.info(enterer.getName() + e); - } - - return false; - - } - - public static boolean LeaveWater(PlayerCharacter leaver) { - - try { - - - Zone zone = ZoneManager.findSmallestZone(leaver.getLoc()); - - float leaveWater = leaver.centerHeight; - - if (leaver.isMoving()) - leaveWater = 1f; - - - if (zone.getSeaLevel() != 0) { - - float localAltitude = leaver.getLoc().y; - - - if (localAltitude + leaveWater < zone.getSeaLevel()) - return false; - } else { - if (leaver.getLoc().y + leaveWater < 0) - return false; - } - } catch (Exception e) { - Logger.info(leaver.getName() + e); - } - - return true; - } - - public static boolean CanBindToBuilding(PlayerCharacter player, int buildingID) { - if (buildingID == 0) - return false; - - Building bindBuilding = BuildingManager.getBuildingFromCache(buildingID); - - if (bindBuilding == null) - return false; - - if (!BuildingManager.playerCanManage(player, bindBuilding)) - return false; - - return true; - } - - public void setGuildTitle(int value) { - if (GuildStatusController.getTitle(this.guildStatus) == value) - return; - DbManager.PlayerCharacterQueries.SET_GUILD_TITLE(this, value); - GuildStatusController.setTitle(guildStatus, value); - } - - public void setFullMember(boolean value) { - if (GuildStatusController.isFullMember(this.guildStatus) == value) - return; - DbManager.PlayerCharacterQueries.SET_FULL_MEMBER(this, value); - GuildStatusController.setFullMember(guildStatus, value); - } + PlayerManager.setGuildLeader(this, guild != null && guild.isGuildLeader(this.getObjectUUID())); - public void setRecruiter(boolean value) { - if (GuildStatusController.isRecruiter(this.guildStatus) == value) - return; - DbManager.PlayerCharacterQueries.SET_RECRUITER(this, value); - GuildStatusController.setRecruiter(guildStatus, value); - } + boolean hasAnniversery = rs.getBoolean("anniversery"); - public void setTaxCollector(boolean value) { - if (GuildStatusController.isTaxCollector(this.guildStatus) == value) - return; - DbManager.PlayerCharacterQueries.SET_TAX_COLLECTOR(this, value); - GuildStatusController.setTaxCollector(guildStatus, value); - } + PlayerManager.setInnerCouncil(this, rs.getBoolean("guild_isInnerCouncil")); + PlayerManager.setFullMember(this, rs.getBoolean("guild_isFullMember")); + PlayerManager.setTaxCollector(this, rs.getBoolean("guild_isTaxCollector")); + PlayerManager.setRecruiter(this, rs.getBoolean("guild_isRecruiter")); + PlayerManager.setGuildTitle(this, rs.getInt("guild_title")); - public void setInnerCouncil(boolean value) { + if (this.account != null) + this.ignoredPlayerIDs = DbManager.PlayerCharacterQueries.GET_IGNORE_LIST(this.account.getObjectUUID(), false); - // dont update if its the same. - if (GuildStatusController.isInnerCouncil(this.guildStatus) == value) - return; + this.strMod.set(rs.getShort("char_strMod")); + this.dexMod.set(rs.getShort("char_dexMod")); + this.conMod.set(rs.getShort("char_conMod")); + this.intMod.set(rs.getShort("char_intMod")); + this.spiMod.set(rs.getShort("char_spiMod")); - DbManager.PlayerCharacterQueries.SET_INNERCOUNCIL(this, value); - GuildStatusController.setInnerCouncil(guildStatus, value); - } + this.bindBuildingID = rs.getInt("char_bindBuilding"); - public void setGuildLeader(boolean value) { - if (GuildStatusController.isGuildLeader(this.guildStatus) == value) - return; + this.hash = rs.getString("hash"); - GuildStatusController.setGuildLeader(guildStatus, value); - if (value == true) { - this.setInnerCouncil(true); - this.setFullMember(true); - } - } - //END -> Guild Status Interface - public void resetGuildStatuses() { - this.setInnerCouncil(false); - this.setFullMember(false); - this.setGuildTitle(0); - this.setTaxCollector(false); - this.setRecruiter(false); - this.setGuildLeader(false); + // For debugging skills + // CharacterSkill.printSkills(this); } /* @@ -1866,7 +425,7 @@ public class PlayerCharacter extends AbstractCharacter { //DeathShroud - if (zone.getSafeZone() == 0) + if (zone != null && zone.getSafeZone() == 0) PowersManager.applyPower(this, this, Vector3fImmutable.ZERO, 1672601862, 40, false); if (doPVPEXP) { @@ -1986,7 +545,7 @@ public class PlayerCharacter extends AbstractCharacter { try { if (SessionManager.getPlayerCharacterByID(this.getObjectUUID()) == null && !this.enteredWorld) { WorldGrid.RemoveWorldObject(this); - this.respawn(false, false, true); + PlayerManager.respawn(this, false, false, true); } else { TargetedActionMsg killmsg = new TargetedActionMsg(this, true); DispatchMessage.dispatchMsgToInterestArea(this, killmsg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); @@ -2044,100 +603,6 @@ public class PlayerCharacter extends AbstractCharacter { } - public void respawn(boolean setAlive, boolean enterWorld, boolean makeCorpse) { - - // Recalculate everything - if(this.timestamps.containsKey("DeathTime")) - this.timestamps.remove("DeathTime"); - - this.recalculatePlayerStats(true); - this.setCombat(false); - - // Set Health to 1/4 max - - - Corpse corpse = null; - - if (makeCorpse) { - try { - corpse = Corpse.makeCorpse(this, enterWorld); - } catch (Exception e) { - Logger.error(e); - } - //if we're not making corpse, just purge inventory. used for characters dead while logged out. - } - - if (!setAlive) { - if (corpse == null && makeCorpse) { - Logger.error("Corpse not created."); - } else { - if (makeCorpse && corpse != null) { - InterestManager.forceLoad(corpse); - } - } - return; - } - - this.setHealth((float) (healthMax * .25)); - this.isAlive.set(true); - - - // Put player in safe mode - // Teleport the player to his bind loc - // or to a ruin as apporpriate. - - Building bindBuilding = BuildingManager.getBuildingFromCache(this.getBindBuildingID()); - - if (enterWorld) { - this.stopMovement(this.getBindLoc()); - } else if (bindBuilding != null) { - if (bindBuilding.getParentZone().equals(ZoneManager.findSmallestZone(this.getLoc()))) - this.teleport(Ruins.getRandomRuin().getLocation()); - else - this.teleport(this.getBindLoc()); - } else // no bind building found for player, teleport to ruins. - this.teleport(Ruins.getRandomRuin().getLocation()); - - this.lastUpdateTime = System.currentTimeMillis(); - this.lastStamUpdateTime = System.currentTimeMillis(); - - this.update(false); - - PowersManager.applyPower(this, this, Vector3fImmutable.ZERO, -1661758934, 40, false); - - if (corpse == null && makeCorpse) { - Logger.error("Corpse not created."); - } else { - if (makeCorpse && corpse != null) { - InterestManager.forceLoad(corpse); - } - } - } - - public Effect addCityEffect(String name, EffectsBase eb, int trains, int duration, boolean onEnter, City city) { - JobContainer jc = null; - if (onEnter) { - NoTimeJob ntj = new NoTimeJob(this, name, eb, trains); //infinite timer - ntj.setEffectSourceType(city.getObjectType().ordinal()); - ntj.setEffectSourceID(city.getObjectUUID()); - jc = new JobContainer(ntj); - } else { - FinishSpireEffectJob fsej = new FinishSpireEffectJob(this, name, eb, trains); - fsej.setEffectSourceType(city.getObjectType().ordinal()); - fsej.setEffectSourceID(city.getObjectUUID()); - jc = JobScheduler.getInstance().scheduleJob(fsej, duration); - } - - if (this.effects.get(name) != null) - this.effects.get(name).cancelJob(); - - Effect eff = new Effect(jc, eb, trains); - this.effects.put(name, eff); - applyAllBonuses(); - eff.sendSpireEffect(this.getClientConnection(), onEnter); - return eff; - } - /** * @return the race */ @@ -2192,7 +657,7 @@ public class PlayerCharacter extends AbstractCharacter { if (ConfigManager.serverType.equals(ServerType.LOGINSERVER)) return Vector3fImmutable.ZERO; - Building bindBuilding = PlayerCharacter.getUpdatedBindBuilding(this); + Building bindBuilding = PlayerManager.getUpdatedBindBuilding(this); //handle rented room binds. @@ -2274,13 +739,6 @@ public class PlayerCharacter extends AbstractCharacter { return beardColor; } - /** - * @return the lfGroup - */ - public boolean isLfGroup() { - return lfGroup; - } - public int getIsLfGroupAsInt() { if (lfGroup) return 2; @@ -2303,33 +761,14 @@ public class PlayerCharacter extends AbstractCharacter { return this.lfGroup; } - public final void setLFGroup(final boolean value) { - this.lfGroup = value; - } - public final boolean isLFGuild() { return this.lfGuild; } - public final void setLFGuild(final boolean value) { - this.lfGuild = value; - } - public final boolean isRecruiting() { return this.recruiting; } - public final void setRecruiting(final boolean value) { - this.recruiting = value; - } - - /** - * @return the lfGuild - */ - public boolean isLfGuild() { - return lfGuild; - } - public final int getHeadlightsAsInt() { if (this.lfGroup) if (this.lfGuild) @@ -2352,12 +791,6 @@ public class PlayerCharacter extends AbstractCharacter { return 0; // No Headlights } - public int getIsLfGuildAsInt() { - if (lfGuild) - return 2; - return 1; - } - public int getStrMax() { return this.statStrMax; } @@ -2372,362 +805,10 @@ public class PlayerCharacter extends AbstractCharacter { public int getIntMax() { return this.statIntMax; - } - - public int getSpiMax() { - return this.statSpiMax; - } - - public void addStr(int amount) { - - boolean worked = false; - short newStr = (short) 0; - while (!worked) { - - if ((this.unusedStatPoints - this.trainedStatPoints) <= 0) - return; - - newStr = (short) (this.statStrBase + amount); - short mod = (short) this.strMod.get(); - short newStrMod = (short) (mod + amount); - - if (newStr > this.statStrMax) { - newStrMod += (this.statStrMax - newStr); - newStr = this.statStrMax; - } - worked = this.strMod.compareAndSet(mod, newStrMod); - } - this.trainedStatPoints++; - this.statStrBase = newStr; - this.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); - this.applyBonuses(); - this.calculateSkills(); - } - - public void addDex(int amount) { - - boolean worked = false; - short newDex = (short) 0; - - while (!worked) { - - if ((this.unusedStatPoints - this.trainedStatPoints) <= 0) - return; - - newDex = (short) (this.statDexBase + amount); - short mod = (short) this.dexMod.get(); - short newDexMod = (short) (mod + amount); - - if (newDex > this.statDexMax) { - newDexMod += (this.statDexMax - newDex); - newDex = this.statDexMax; - } - - worked = this.dexMod.compareAndSet(mod, newDexMod); - } - this.trainedStatPoints++; - this.statDexBase = newDex; - this.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); - this.applyBonuses(); - this.calculateSkills(); - } - - public void addCon(int amount) { - boolean worked = false; - short newCon = (short) 0; - while (!worked) { - - if ((this.unusedStatPoints - this.trainedStatPoints) <= 0) - return; - - newCon = (short) (this.statConBase + amount); - short mod = (short) this.conMod.get(); - short newConMod = (short) (mod + amount); - - if (newCon > this.statConMax) { - newConMod += (this.statConMax - newCon); - newCon = this.statConMax; - } - worked = this.conMod.compareAndSet(mod, newConMod); - } - this.trainedStatPoints++; - this.statConBase = newCon; - this.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); - this.applyBonuses(); - this.calculateSkills(); - } - - public void addInt(int amount) { - boolean worked = false; - short newInt = (short) 0; - while (!worked) { - - if ((this.unusedStatPoints - this.trainedStatPoints) <= 0) - return; - - newInt = (short) (this.statIntBase + amount); - short mod = (short) this.intMod.get(); - short newIntMod = (short) (mod + amount); - - if (newInt > this.statIntMax) { - newIntMod += (this.statIntMax - newInt); - newInt = this.statIntMax; - } - worked = this.intMod.compareAndSet(mod, newIntMod); - } - this.trainedStatPoints++; - this.statIntBase = newInt; - this.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); - this.applyBonuses(); - this.calculateSkills(); - } - - public void addSpi(int amount) { - boolean worked = false; - short newSpi = (short) 0; - - while (!worked) { - - if ((this.unusedStatPoints - this.trainedStatPoints) <= 0) - return; - - newSpi = (short) (this.statSpiBase + amount); - short mod = (short) this.spiMod.get(); - short newSpiMod = (short) (mod + amount); - - if (newSpi > this.statSpiMax) { - newSpiMod += (this.statSpiMax - newSpi); - newSpi = this.statSpiMax; - } - worked = this.spiMod.compareAndSet(mod, newSpiMod); - } - this.trainedStatPoints++; - this.statSpiBase = newSpi; - this.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); - this.applyBonuses(); - this.calculateSkills(); - } - - public boolean refineStr() { - boolean worked = false; - short newStr = (short) 0; - - while (!worked) { - - newStr = (short) (this.statStrBase - 1); - short mod = (short) this.strMod.get(); - - if (mod == 0) - return false; - - short newStrMod = (short) (mod - 1); - - if (newStr < this.statStrMin) - return false; - - if (!canRefineLower(MBServerStatics.STAT_STR_ID)) - return false; - - worked = this.strMod.compareAndSet(mod, newStrMod); - } - this.trainedStatPoints--; - this.statStrBase = newStr; - this.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); - this.applyBonuses(); - this.calculateSkills(); - return true; - } - - public boolean refineDex() { - boolean worked = false; - short newDex = (short) 0; - - while (!worked) { - newDex = (short) (this.statDexBase - 1); - short mod = (short) this.dexMod.get(); - - if (mod == 0) - return false; - - short newDexMod = (short) (mod - 1); - - if (newDex < this.statDexMin) - return false; - - if (!canRefineLower(MBServerStatics.STAT_DEX_ID)) - return false; - - worked = this.dexMod.compareAndSet(mod, newDexMod); - } - this.trainedStatPoints--; - this.statDexBase = newDex; - this.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); - this.applyBonuses(); - this.calculateSkills(); - return true; - } - - public boolean refineCon() { - boolean worked = false; - short newCon = (short) 0; - - while (!worked) { - newCon = (short) (this.statConBase - 1); - short mod = (short) this.conMod.get(); - - if (mod == 0) - return false; - - short newConMod = (short) (mod - 1); - - if (newCon < this.statConMin) - return false; - - if (!canRefineLower(MBServerStatics.STAT_CON_ID)) - return false; - - worked = this.conMod.compareAndSet(mod, newConMod); - } - this.trainedStatPoints--; - this.statConBase = newCon; - this.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); - this.applyBonuses(); - this.calculateSkills(); - return true; - } - - public boolean refineInt(RefineMsg msg) { - boolean worked = false; - short newInt = (short) 0; - - while (!worked) { - newInt = (short) (this.statIntBase - 1); - short mod = (short) this.intMod.get(); - - if (mod == 0) - return false; - short newIntMod = (short) (mod - - 1); - - if (newInt < this.statIntMin) - return false; - - if (!canRefineLower(MBServerStatics.STAT_INT_ID)) - return false; - - worked = this.intMod.compareAndSet(mod, newIntMod); - } - this.trainedStatPoints--; - this.statIntBase = newInt; - this.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); - - verifySkillMax(msg); - - this.applyBonuses(); - this.calculateSkills(); - return true; - } - - public boolean refineSpi() { - boolean worked = false; - short newSpi = (short) 0; - while (!worked) { - newSpi = (short) (this.statSpiBase - 1); - short mod = (short) this.spiMod.get(); - if (mod == 0) - return false; - short newSpiMod = (short) (mod - 1); - if (newSpi < this.statSpiMin) - return false; - if (!canRefineLower(MBServerStatics.STAT_SPI_ID)) - return false; - worked = this.spiMod.compareAndSet(mod, newSpiMod); - } - this.trainedStatPoints--; - this.statSpiBase = newSpi; - this.addDatabaseJob("Stats", MBServerStatics.THIRTY_SECONDS); - this.applyBonuses(); - this.calculateSkills(); - return true; - } - - //this verifies stat doesn't fall too low to keep runes applied while refining - private boolean canRefineLower(int stat) { - for (CharacterRune cr : this.runes) { - if (cr != null) { - RuneBase rb = cr.getRuneBase(); - if (rb != null) { - ArrayList attrs = rb.getAttrs(); - - if (attrs != null) - for (RuneBaseAttribute rba : attrs) { - int attrID = rba.getAttributeID(); - int mod = rba.getModValue(); - if (stat == MBServerStatics.STAT_STR_ID) { - if (attrID == MBServerStatics.RUNE_STR_MIN_NEEDED_ATTRIBUTE_ID && ((int) this.statStrBase <= mod)) - return false; - } else if (stat == MBServerStatics.STAT_DEX_ID) { - if (attrID == MBServerStatics.RUNE_DEX_MIN_NEEDED_ATTRIBUTE_ID && ((int) this.statDexBase <= mod)) - return false; - } else if (stat == MBServerStatics.STAT_CON_ID) { - if (attrID == MBServerStatics.RUNE_CON_MIN_NEEDED_ATTRIBUTE_ID && ((int) this.statConBase <= mod)) - return false; - } else if (stat == MBServerStatics.STAT_INT_ID) { - if (attrID == MBServerStatics.RUNE_INT_MIN_NEEDED_ATTRIBUTE_ID && ((int) this.statIntBase <= mod)) - return false; - } else if (stat == MBServerStatics.STAT_SPI_ID) - if (attrID == MBServerStatics.RUNE_SPI_MIN_NEEDED_ATTRIBUTE_ID && ((int) this.statSpiBase <= mod)) - return false; - } - } - } - } - - return true; - } - - //checked on refining int to see if skills need refined also. - private void verifySkillMax(RefineMsg msg) { - - ConcurrentHashMap skills = getSkills(); - - //make sure no skills are over the max number of trains - int maxTrains = CharacterSkill.getMaxTrains((int) this.statIntBase); - - RefineMsg rm = new RefineMsg(msg.getNpcType(), msg.getNpcID(), 0, 0); - - for (CharacterSkill skill : skills.values()) { - - while (skill.getNumTrains() > maxTrains) { - boolean worked = skill.refine(this, false); //refine skill, do not recalculate everything - if (worked) { - rm.setToken(skill.getToken()); - - Dispatch dispatch = Dispatch.borrow(this, rm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - } else { - Logger.error("Failed to force refine of skill " + skill.getObjectUUID() + " by character " + this.getObjectUUID()); - break; - } - } - } - } - - public int getClassToken() { - if (this.promotionClass != null) - return this.promotionClass.getToken(); - else if (this.baseClass != null) - return this.baseClass.getToken(); - return 0; - } - - public int getRaceToken() { - - if (this.race == null) - return 0; + } - return this.race.getToken(); + public int getSpiMax() { + return this.statSpiMax; } public void setLastTarget(GameObjectType type, int id) { @@ -2895,7 +976,7 @@ public class PlayerCharacter extends AbstractCharacter { float speed; - if (this.isFlying()) + if (PlayerManager.isFlying(this)) if (this.walkMode) { speed = race.getRaceType().getRunSpeed().getFlyWalk(); } else { @@ -2924,247 +1005,6 @@ public class PlayerCharacter extends AbstractCharacter { return endSpeed; } - public synchronized void grantXP(int xp) { - if(this.promotionClass == null && this.level == 10){ - this.setOverFlowEXP(0); - this.update(false); - this.incVer(); - this.recalculate(); - this.calculateMaxHealthManaStamina(); - this.setHealth(this.healthMax); - this.mana.set(this.manaMax); - this.stamina.set(this.staminaMax); - //LoadJob.reloadCharacter(this); - DbManager.PlayerCharacterQueries.SET_PROPERTY(this, "char_experience", this.exp); - // updateDatabase(); - DbManager.AccountQueries.INVALIDATE_LOGIN_CACHE(this.getObjectUUID(), "character"); - return; - } - // Stop players from getting experience past the cap - if (this.exp + xp >= Experience.getBaseExperience(MBServerStatics.LEVELCAP)) - xp = Experience.getBaseExperience(MBServerStatics.LEVELCAP) - this.exp + 1; - - if (xp == 0) - xp = 1; - - boolean isNewLevel = false; - boolean charReloadRequired = false; - int remainingXP = xp; - int neededXP = 0; - - // handle players that have not yet promoted. - ClientConnection origin = this.getClientConnection(); - - //not promoted at level 10, start checking for negative EXP - if (this.promotionClass == null && this.getLevel() == 10) { - - if (this.getExp() == Experience.getBaseExperience(11)) { - if (this.overFlowEXP == 110000) - return; - - if (this.overFlowEXP + xp > 110000) { - remainingXP = 110000 - this.overFlowEXP; - this.overFlowEXP = 110000; - - - } else { - this.overFlowEXP += remainingXP; - } - - GrantExperienceMsg gem = new GrantExperienceMsg(this, remainingXP); - Dispatch dispatch = Dispatch.borrow(this, gem); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - this.addDatabaseJob("EXP", MBServerStatics.FIVE_MINUTES); - return; - //didnt reach level 11 EXP to start overflow, add exp normally till we get here; - } else { - - //Player exp begins negative exp, add remaing exp after level 11 to overflow - if (this.getExp() + remainingXP >= Experience.getBaseExperience(11)) { - - this.overFlowEXP = remainingXP - (Experience.getBaseExperience(11) - this.getExp()); - this.exp = Experience.getBaseExperience(11); - - GrantExperienceMsg grantExperienceMsg = new GrantExperienceMsg(this, remainingXP); - Dispatch dispatch = Dispatch.borrow(this, grantExperienceMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - this.addDatabaseJob("EXP", MBServerStatics.FIVE_MINUTES); - return; - - //didnt reach negative exp yet, just do normal exp gain. - } else { - this.exp += remainingXP; - GrantExperienceMsg grantExperienceMsg = new GrantExperienceMsg(this, remainingXP); - remainingXP = 0; - Dispatch dispatch = Dispatch.borrow(this, grantExperienceMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - this.addDatabaseJob("EXP", MBServerStatics.FIVE_MINUTES); - return; - } - } - } - - if (this.overFlowEXP > 0) { - - int nextLevel; - - if (level == 10) - nextLevel = 12; - else - nextLevel = level + 2; - - int nextLevelEXP = Experience.getBaseExperience(nextLevel); - - // if overflow > 0, u have level 11 experience + overflow, but level is still 10 due to just promoting. - //Use level + 2 experience for next level. - this.overFlowEXP += 1; - - if (this.getExp() + this.overFlowEXP >= nextLevelEXP) { - - int expToNextLevel = nextLevelEXP - this.getExp(); - this.overFlowEXP -= expToNextLevel; - this.exp += expToNextLevel; - this.level++; - charReloadRequired = true; - - GrantExperienceMsg grantExperienceMsg = new GrantExperienceMsg(this, 1); - Dispatch dispatch = Dispatch.borrow(this, grantExperienceMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - SetObjectValueMsg upm = new SetObjectValueMsg(this, 9); - DispatchMessage.dispatchMsgToInterestArea(this, upm, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); - checkGuildStatus(); - this.addDatabaseJob("EXP", MBServerStatics.FIVE_MINUTES); - // double overflow exp used up, remaining overflow will just add to level + 1. - } else if (this.getExp() + this.overFlowEXP >= Experience.getBaseExperience(level + 1)) { - int nextExperience = Experience.getBaseExperience(level + 1) + this.overFlowEXP; - this.exp = nextExperience; - this.level++; - charReloadRequired = true; - this.overFlowEXP = 0; - GrantExperienceMsg grantExperienceMsg = new GrantExperienceMsg(this, 1); - Dispatch dispatch = Dispatch.borrow(this, grantExperienceMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - SetObjectValueMsg upm = new SetObjectValueMsg(this, 9); - DispatchMessage.dispatchMsgToInterestArea(this, upm, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); - checkGuildStatus(); - this.addDatabaseJob("EXP", MBServerStatics.FIVE_MINUTES); - } - - } else { - // Hand out each Level one at a time. - isNewLevel = Experience.getLevel(exp + remainingXP) > this.getLevel(); - - if (isNewLevel) { - neededXP = Experience.getBaseExperience(this.getLevel() + 1) - this.exp; - - charReloadRequired = true; - this.exp += neededXP; - this.level++; - - GrantExperienceMsg grantExperienceMsg = new GrantExperienceMsg(this, neededXP); - Dispatch dispatch = Dispatch.borrow(this, grantExperienceMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - remainingXP -= neededXP; - - //Send newLevel. - SetObjectValueMsg upm = new SetObjectValueMsg(this, 9); - DispatchMessage.dispatchMsgToInterestArea(this, upm, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); - checkGuildStatus(); - } else { - - this.exp += remainingXP; - GrantExperienceMsg grantExperienceMsg = new GrantExperienceMsg(this, remainingXP); - remainingXP = 0; - Dispatch dispatch = Dispatch.borrow(this, grantExperienceMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - this.addDatabaseJob("EXP", MBServerStatics.FIVE_MINUTES); - } - } - - if (charReloadRequired) { - this.update(false); - this.incVer(); - this.recalculate(); - this.calculateMaxHealthManaStamina(); - this.setHealth(this.healthMax); - this.mana.set(this.manaMax); - this.stamina.set(this.staminaMax); - //LoadJob.reloadCharacter(this); - DbManager.PlayerCharacterQueries.SET_PROPERTY(this, "char_experience", this.exp); - // updateDatabase(); - DbManager.AccountQueries.INVALIDATE_LOGIN_CACHE(this.getObjectUUID(), "character"); - } - } - - //This checks if a player meets the requirements to be in current guild. - public void checkGuildStatus() { - - Guild g = this.guild; - - if (g == null || g.isEmptyGuild() || GuildStatusController.isGuildLeader(guildStatus)) - return; - - //check level - int curLevel = (int) getPCLevel(); - if (curLevel < g.getRepledgeMin() || curLevel >= g.getRepledgeKick()) { - //TODO kick from guild - g.removePlayer(this, GuildHistoryType.LEAVE); - ChatManager.chatGuildInfo(this, "You no longer meet the level requirements for the guild."); - } - } - - public void calculateSpeedMod() { - // get base race speed modifer - - - //this is retarded. *** Refactor - // if (this.race != null) { - // int ID = this.race.getObjectUUID(); - // if (ID == 2004 || ID == 2005) - // this.raceRunMod = 1.21f; // centaur run bonus 22% - //// else if (ID == 2017) - //// this.raceRunMod = 1.14f; // mino run bonus 15% - // else - // this.raceRunMod = 1; - // } else - // this.raceRunMod = 1; - - - float bonus = 1f; - - // // TODO: hardcoded, as didnt have time to introduce DB column to base object - // if (baseClass.getName().equals("Fighter") || baseClass.getName().equals("Rogue")) - // bonus += .05f; - - // get running skill - if (this.skills != null) { - CharacterSkill running = this.skills.get("Running"); - if (running != null) { - - float runningBonus = (float) (Math.log(Math.round(running.getModifiedAmount()) * .01f) / Math.log(2) * .50f); - runningBonus = (float) (Math.pow(2, runningBonus) - 1); - runningBonus += 1; - runningBonus *= .25f; - bonus += runningBonus; - - } - } - - if (this.bonuses != null) - // get rune and effect bonuses - bonus += this.bonuses.getFloatPercentNullZero(ModType.Speed, SourceType.None); - - // TODO get equip bonus - this.update(false); - this.speedMod = bonus; - } - public ClientConnection getClientConnection() { return SessionManager.getClientConnection(this); } @@ -3250,10 +1090,6 @@ public class PlayerCharacter extends AbstractCharacter { return this.loadedStaticObjects; } - public void setLoadedStaticObjects(HashSet value) { - this.loadedStaticObjects = value; - } - public boolean isTeleportMode() { return teleportMode; } @@ -3262,19 +1098,6 @@ public class PlayerCharacter extends AbstractCharacter { this.teleportMode = teleportMode; } - // public ConcurrentHashMap - // getRecycleTimers() { - // return this.recycleTimers; - // } - // public UsePowerJob getLastPower() { - // return this.lastPower; - // } - // public void setLastPower(UsePowerJob value) { - // this.lastPower = value; - // } - // public void clearLastPower() { - // this.lastPower = null; - // } public long chatFloodTime(int chatOpcode, long chatTimeMilli, int qtyToSave) { if (qtyToSave < 1) return 0L; // disabled @@ -3411,7 +1234,7 @@ public class PlayerCharacter extends AbstractCharacter { this.calculateAtrDefenseDamage(); //calculate movement bonus - this.calculateSpeedMod(); + PlayerManager.calculateSpeedMod(this); // recalculate Max Health/Mana/Stamina this.calculateMaxHealthManaStamina(); @@ -3439,7 +1262,7 @@ public class PlayerCharacter extends AbstractCharacter { } //This is run to auto-fix any overage on skill training. - private void recalculateTrains() { + public void recalculateTrains() { int trainsAvailable = CharacterSkill.getTrainsAvailable(this); if (trainsAvailable < 0) { @@ -3726,7 +1549,7 @@ public class PlayerCharacter extends AbstractCharacter { float intVal = this.statIntBase; float spiVal = this.statSpiBase; - this.dexPenalty = getDexPenalty(); + float dexPenalty = getDexPenalty(); // TODO modify for equipment if (this.bonuses != null) { @@ -3738,7 +1561,7 @@ public class PlayerCharacter extends AbstractCharacter { spiVal += Math.round(this.bonuses.getFloat(ModType.Attr, SourceType.Spirit)); // apply dex penalty for armor - dexVal *= this.dexPenalty; + dexVal *= dexPenalty; // modify percent amounts. DO THIS LAST! strVal *= (1 + this.bonuses.getFloatPercentAll(ModType.Attr, SourceType.Strength)); @@ -3749,7 +1572,7 @@ public class PlayerCharacter extends AbstractCharacter { } else // apply dex penalty for armor - dexVal *= this.dexPenalty; + dexVal *= dexPenalty; // Set current stats this.statStrCurrent = (strVal < 1) ? (short) 1 : (short) strVal; @@ -3775,12 +1598,12 @@ public class PlayerCharacter extends AbstractCharacter { ConcurrentHashMap equipped = this.charItemManager.getEquipped(); float dexPenalty = 0f; - dexPenalty += getDexPenalty(equipped.get(MBServerStatics.SLOT_HELMET)); - dexPenalty += getDexPenalty(equipped.get(MBServerStatics.SLOT_CHEST)); - dexPenalty += getDexPenalty(equipped.get(MBServerStatics.SLOT_ARMS)); - dexPenalty += getDexPenalty(equipped.get(MBServerStatics.SLOT_GLOVES)); - dexPenalty += getDexPenalty(equipped.get(MBServerStatics.SLOT_LEGGINGS)); - dexPenalty += getDexPenalty(equipped.get(MBServerStatics.SLOT_FEET)); + dexPenalty += PlayerManager.getDexPenalty(equipped.get(MBServerStatics.SLOT_HELMET)); + dexPenalty += PlayerManager.getDexPenalty(equipped.get(MBServerStatics.SLOT_CHEST)); + dexPenalty += PlayerManager.getDexPenalty(equipped.get(MBServerStatics.SLOT_ARMS)); + dexPenalty += PlayerManager.getDexPenalty(equipped.get(MBServerStatics.SLOT_GLOVES)); + dexPenalty += PlayerManager.getDexPenalty(equipped.get(MBServerStatics.SLOT_LEGGINGS)); + dexPenalty += PlayerManager.getDexPenalty(equipped.get(MBServerStatics.SLOT_FEET)); return (1 - (dexPenalty / 100)); } @@ -3939,8 +1762,8 @@ public class PlayerCharacter extends AbstractCharacter { } else this.rangeHandTwo = -1; // set to do not attack - skillPercentage = getModifiedAmount(this.skills.get("Unarmed Combat")); - masteryPercentage = getModifiedAmount(this.skills.get("Unarmed Combat Mastery")); + skillPercentage = PlayerManager.getModifiedAmount(this.skills.get("Unarmed Combat")); + masteryPercentage = PlayerManager.getModifiedAmount(this.skills.get("Unarmed Combat Mastery")); if (masteryPercentage == 0f) mastDam = CharacterSkill.getQuickMastery(this, "Unarmed Combat Mastery"); else @@ -3963,8 +1786,8 @@ public class PlayerCharacter extends AbstractCharacter { this.rangeHandTwo *= range_bonus; } - skillPercentage = getModifiedAmount(this.skills.get(wb.getSkillRequired())); - masteryPercentage = getModifiedAmount(this.skills.get(wb.getMastery())); + skillPercentage = PlayerManager.getModifiedAmount(this.skills.get(wb.getSkillRequired())); + masteryPercentage = PlayerManager.getModifiedAmount(this.skills.get(wb.getMastery())); if (masteryPercentage == 0f) mastDam = 0f; // mastDam = CharacterSkill.getQuickMastery(this, wb.getMastery()); @@ -4512,40 +2335,6 @@ public class PlayerCharacter extends AbstractCharacter { return !this.isAlive(); } - public void ResetLevel(short targetLevel) { - - if (targetLevel > 13) { - ChatManager.chatSystemError(this, "Please choose a level between 1 and 13."); - return; - } - this.promotionClass = null; - if (targetLevel > 10) { - this.level = 10; - this.exp = Experience.getBaseExperience(11); - int maxEXP = Experience.getBaseExperience(targetLevel); //target level exp; - this.overFlowEXP = maxEXP - this.exp; - } else { - this.level = targetLevel; - this.exp = Experience.getBaseExperience(level); - this.overFlowEXP = 0; - } - - - for (CharacterSkill skill : this.getSkills().values()) { - skill.reset(this, true); - } - - for (CharacterPower power : this.getPowers().values()) { - power.reset(this); - } - - this.recalculatePlayerStats(initialized); - this.recalculate(); - - ChatManager.chatSystemInfo(this, "Character reset to " + targetLevel + ". All training points have been refunded. Relog to update changes on client."); - - } - @Override public void removeFromCache() { Logger.info("Removing " + this.getName() + " from Object Cache."); @@ -4582,21 +2371,6 @@ public class PlayerCharacter extends AbstractCharacter { super.removeFromCache(); } - public void storeIgnoreListDB() { - - } - - public void updateSkillsAndPowersToDatabase() { - if (this.skills != null) - for (CharacterSkill skill : this.skills.values()) { - DbManager.CharacterSkillQueries.UPDATE_TRAINS(skill); - if (this.powers != null) - for (CharacterPower power : this.powers.values()) { - DbManager.CharacterPowerQueries.UPDATE_TRAINS(power); - } - } - } - @Override public void updateDatabase() { } @@ -4614,7 +2388,7 @@ public class PlayerCharacter extends AbstractCharacter { } @Override - protected ConcurrentHashMap initializePowers() { + public ConcurrentHashMap initializePowers() { return DbManager.CharacterPowerQueries.GET_POWERS_FOR_CHARACTER(this); } @@ -4643,7 +2417,7 @@ public class PlayerCharacter extends AbstractCharacter { tmpLevel = (short) Math.min(tmpLevel, 75); while (this.level < tmpLevel) { - grantXP(Experience.getBaseExperience(tmpLevel) - this.exp); + PlayerManager.grantXP(this, Experience.getBaseExperience(tmpLevel) - this.exp); } } @@ -4678,7 +2452,7 @@ public class PlayerCharacter extends AbstractCharacter { this.setBindBuildingID(cityTol != null ? cityTol.getObjectUUID() : 0); //update binds, checks for nation tol if guild tol == null; - PlayerCharacter.getUpdatedBindBuilding(this); + PlayerManager.getUpdatedBindBuilding(this); DbManager.AccountQueries.INVALIDATE_LOGIN_CACHE(this.getObjectUUID(), "character"); @@ -4705,66 +2479,6 @@ public class PlayerCharacter extends AbstractCharacter { } } - public boolean commandSiegeMinion(Mob toCommand) { - if (!toCommand.isSiege()) - return false; - if (toCommand.isPet() || !toCommand.isAlive()) - return false; - - if (toCommand.getGuild().getNation() != this.getGuild().getNation()) - return false; - - if (this.pet != null) { - Mob currentPet = this.pet; - if (!currentPet.isSiege()) { - - currentPet.setCombatTarget(null); - - if (currentPet.getParentZone() != null) - - currentPet.getParentZone().zoneMobSet.remove(currentPet); - - try { - currentPet.clearEffects(); - } catch (Exception e) { - Logger.error(e.getMessage()); - } - currentPet.playerAgroMap.clear(); - WorldGrid.RemoveWorldObject(currentPet); - DbManager.removeFromCache(currentPet); - - } else if (currentPet.isSiege()) { - currentPet.agentType = AIAgentType.MOBILE; - currentPet.setOwner(null); - currentPet.setCombatTarget(null); - if (currentPet.isAlive()) - WorldGrid.updateObject(currentPet); - } - } - - toCommand.setPet(this, false); - this.setPet(toCommand); - toCommand.setCombatTarget(null); - PetMsg petMsg = new PetMsg(6, toCommand); - Dispatch dispatch = Dispatch.borrow(this, petMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - - if (toCommand.isAlive()) - WorldGrid.updateObject(toCommand); - return true; - } - - // Method is called by Server Heartbeat simulation tick. - // Stat regen and transform updates should go in here. - - public boolean isNoTeleScreen() { - return noTeleScreen; - } - - public void setNoTeleScreen(boolean noTeleScreen) { - this.noTeleScreen = noTeleScreen; - } - private double getDeltaTime() { return (System.currentTimeMillis() - lastUpdateTime) * .001f; @@ -4775,73 +2489,6 @@ public class PlayerCharacter extends AbstractCharacter { return (System.currentTimeMillis() - lastStamUpdateTime) * .001f; } - public boolean isFlying() { - - return this.getAltitude() > 0; - - } - - public boolean isSwimming() { - - // If char is flying they aren't quite swimming - try { - if (this.isFlying()) - return false; - - Zone zone = ZoneManager.findSmallestZone(this.getLoc()); - - if (zone.getSeaLevel() != 0) { - - float localAltitude = this.getLoc().y + this.centerHeight; - if (localAltitude < zone.getSeaLevel()) - return true; - } else { - if (this.getLoc().y + this.centerHeight < 0) - return true; - } - } catch (Exception e) { - Logger.info(this.getName() + e); - } - - return false; - } - - public boolean isSwimming(Vector3fImmutable currentLoc) { - - // If char is flying they aren't quite swimming - try { - - float localAltitude = HeightMap.getWorldHeight(currentLoc); - - Zone zone = ZoneManager.findSmallestZone(currentLoc); - - if (zone.getSeaLevel() != 0) { - - if (localAltitude < zone.getSeaLevel()) - return true; - } else { - if (localAltitude < 0) - return true; - } - } catch (Exception e) { - Logger.info(this.getName() + e); - } - - return false; - } - - private static void forceRespawn(PlayerCharacter sourcePlayer) throws MsgSendException { - - if (sourcePlayer == null) - return; - try { - sourcePlayer.getClientConnection().disconnect(); - } catch (Exception e) { - - } - - } - @Override public void update(Boolean newSystem) { @@ -4855,7 +2502,7 @@ public class PlayerCharacter extends AbstractCharacter { if(!this.timestamps.containsKey("DeathTime")){ this.timestamps.put("DeathTime",System.currentTimeMillis()); }else if((System.currentTimeMillis() - this.timestamps.get("DeathTime")) > 600000) - forceRespawn(this); + PlayerManager.forceRespawn(this); return; } this.updateLocation(); @@ -4864,27 +2511,27 @@ public class PlayerCharacter extends AbstractCharacter { if (this.getStamina() < 10) { if (this.getAltitude() > 0 || this.getDesiredAltitude() > 0) { - PlayerCharacter.GroundPlayer(this); + PlayerManager.GroundPlayer(this); this.updateRegen(); } } RealmMap.updateRealm(this); - this.updateBlessingMessage(); + PlayerManager.updateBlessingMessage(this); this.safeZone = this.isInSafeZone(); if(!this.timestamps.containsKey("nextBoxCheck")) this.timestamps.put("nextBoxCheck", System.currentTimeMillis() + 10000); if(!this.isBoxed && this.timestamps.get("nextBoxCheck") < System.currentTimeMillis()) { - this.isBoxed = checkIfBoxed(this); + this.isBoxed = PlayerManager.checkIfBoxed(this); this.timestamps.put("nextBoxCheck", System.currentTimeMillis() + 10000); } if(this.level < 10 && this.enteredWorld) { // this.setLevel((short) 10); while (this.level < 10) { - grantXP(Experience.getBaseExperience(this.level + 1) - this.exp); + PlayerManager.grantXP(this, Experience.getBaseExperience(this.level + 1) - this.exp); } if(this.charItemManager != null && this.charItemManager.getGoldInventory() != null && this.charItemManager.getGoldInventory().getNumOfItems() < 1000) { this.getCharItemManager().addGoldToInventory(1000, false); @@ -4897,10 +2544,10 @@ public class PlayerCharacter extends AbstractCharacter { PowersManager.applyPower(this, this, Vector3fImmutable.ZERO, 1672601862, 40, false); } - if(this.isFlying()){ + if(PlayerManager.isFlying(this)){ //if (!AbstractCharacter.CanFly(this)) { if(this.effects.containsKey("MoveBuff")){ - GroundPlayer(this); + PlayerManager.GroundPlayer(this); //ChatManager.chatSystemInfo(this, "You Cannot Fly While Having A MovementBuff"); } } @@ -4912,47 +2559,7 @@ public class PlayerCharacter extends AbstractCharacter { } } } - public static void unboxPlayer(PlayerCharacter player){ - String machineID = player.getClientConnection().machineID; - ArrayList sameMachine = new ArrayList<>(); - for(PlayerCharacter pc : SessionManager.getAllActivePlayerCharacters()){ - if(!pc.equals(player) && pc. isActive && pc.isEnteredWorld() && pc.getClientConnection().machineID.equals(machineID)){ - sameMachine.add(pc); - } - } - - for(PlayerCharacter pc : sameMachine) - pc.isBoxed = true; - - player.isBoxed = false; - if(player.containsEffect(1672601862)) { - player.removeEffectBySource(EffectSourceType.DeathShroud,41,false); - } - - } - public static boolean checkIfBoxed(PlayerCharacter player){ - if(ConfigManager.MB_WORLD_TESTMODE.getValue().equals("true")) { - return false; - } - try { - String machineID = player.getClientConnection().machineID; - ArrayList sameMachine = new ArrayList<>(); - for (PlayerCharacter pc : SessionManager.getAllActivePlayerCharacters()) { - if (!pc.equals(player) && pc.isActive && pc.isEnteredWorld() && pc.getClientConnection().machineID.equals(machineID)) { - sameMachine.add(pc); - } - } - - boolean boxed = false; - for (PlayerCharacter pc : sameMachine) - if (!pc.isBoxed) - boxed = true; - return boxed; - }catch(Exception e){ - return false; - } - } @Override public void updateFlight() { @@ -4984,34 +2591,6 @@ public class PlayerCharacter extends AbstractCharacter { this.loc = this.loc.setY(HeightMap.getWorldHeight(this) + this.getAltitude()); } - public boolean hasBoon() { - for (Effect eff : this.getEffects().values()) { - if (eff.getPowerToken() == -587743986 || eff.getPowerToken() == -1660519801 || eff.getPowerToken() == -1854683250) - return true; - } - return false; - } - - public void updateBlessingMessage() { - - if (this.getTimeStamp("RealmClaim") > System.currentTimeMillis()) - return; - - int count = 0; - - for (Effect eff : this.getEffects().values()) { - if (eff.getPowerToken() == -587743986 || eff.getPowerToken() == -1660519801 || eff.getPowerToken() == -1854683250) - count++; - } - - if (count > 0) { - this.timestamps.put("RealmClaim", DateTime.now().plusMinutes(3).getMillis()); - for (PlayerCharacter toSend : SessionManager.getAllActivePlayerCharacters()) { - ChatManager.chatSystemInfo(toSend, this.getCombinedName() + " is seeking to claim a realm and already has " + count + " blessngs!"); - } - } - } - @Override public void updateLocation() { @@ -5062,7 +2641,7 @@ public class PlayerCharacter extends AbstractCharacter { if (this.enteredWorld) { if (!this.lastSwimming) { - boolean enterWater = PlayerCharacter.enterWater(this); + boolean enterWater = PlayerManager.enterWater(this); if (enterWater) { this.lastSwimming = enterWater; @@ -5070,7 +2649,7 @@ public class PlayerCharacter extends AbstractCharacter { } } else { - if (PlayerCharacter.LeaveWater(this)) { + if (PlayerManager.LeaveWater(this)) { this.lastSwimming = false; if (!this.isMoving()) MovementManager.sendRWSSMsg(this); @@ -5078,7 +2657,7 @@ public class PlayerCharacter extends AbstractCharacter { } - boolean breathe = PlayerCharacter.CanBreathe(this); + boolean breathe = PlayerManager.CanBreathe(this); if (breathe != this.canBreathe) { this.canBreathe = breathe; @@ -5088,7 +2667,7 @@ public class PlayerCharacter extends AbstractCharacter { } //char is flying - if (this.isFlying() == true) { + if (PlayerManager.isFlying(this) == true) { this.movementState = MovementState.FLYING; return; } @@ -5147,7 +2726,7 @@ public class PlayerCharacter extends AbstractCharacter { else manaRegen = 0; - if (!PlayerCharacter.CanBreathe(this)) + if (!PlayerManager.CanBreathe(this)) stamRegen = MBServerStatics.STAMINA_REGEN_SWIM; else if ((!this.isCasting() && !this.isItemCasting()) || this.lastMovementState.equals(MovementState.FLYING)) stamRegen = MBServerStatics.STAMINA_REGEN_IDLE * getRegenModifier(ModType.StaminaRecoverRate); @@ -5255,7 +2834,7 @@ public class PlayerCharacter extends AbstractCharacter { // Are we drowning? if ((this.getStamina() <= 0) - && (PlayerCharacter.CanBreathe(this) == false)) + && (PlayerManager.CanBreathe(this) == false)) healthRegen = (this.healthMax * -.03f); // Multiple regen values by current deltaTime @@ -5331,7 +2910,7 @@ public class PlayerCharacter extends AbstractCharacter { switch (this.movementState) { case IDLE: - if (!PlayerCharacter.CanBreathe(this)) + if (!PlayerManager.CanBreathe(this)) stamRegen = MBServerStatics.STAMINA_REGEN_SWIM; else if ((!this.isCasting() && !this.isItemCasting()) || this.lastMovementState.equals(MovementState.FLYING)) stamRegen = MBServerStatics.STAMINA_REGEN_IDLE * getRegenModifier(ModType.StaminaRecoverRate); @@ -5427,23 +3006,6 @@ public class PlayerCharacter extends AbstractCharacter { return movementState; } - public boolean isHasAnniversery() { - return hasAnniversery; - } - - public void setHasAnniversery(boolean hasAnniversery) { - DbManager.PlayerCharacterQueries.SET_ANNIVERSERY(this, hasAnniversery); - this.hasAnniversery = hasAnniversery; - } - - public int getSpamCount() { - return spamCount; - } - - public void setSpamCount(int spamCount) { - this.spamCount = spamCount; - } - public String getHash() { return hash; } @@ -5485,29 +3047,6 @@ public class PlayerCharacter extends AbstractCharacter { this.guildHistory = guildHistory; } - public void moveTo(Vector3fImmutable endLoc) { - this.setInBuilding(-1); - this.setInFloorID(-1); - MoveToPointMsg moveToMsg = new MoveToPointMsg(); - moveToMsg.setStartCoord(this.getLoc()); - moveToMsg.setEndCoord(endLoc); - moveToMsg.setInBuilding(-1); - moveToMsg.setUnknown01(-1); - moveToMsg.setSourceType(GameObjectType.PlayerCharacter.ordinal()); - moveToMsg.setSourceID(this.getObjectUUID()); - - Dispatch dispatch = Dispatch.borrow(this, moveToMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - - try { - MovementManager.movement(moveToMsg, this); - } catch (MsgSendException e) { - // TODO Auto-generated catch block - Logger.error("Player.MoveTo", this.getName() + " tripped error " + e.getMessage()); - } - - } - public void updateScaleHeight() { float strengthScale = 0; @@ -5544,10 +3083,6 @@ public class PlayerCharacter extends AbstractCharacter { this.overFlowEXP = overFlowEXP; } - public MovementState getLastMovementState() { - return lastMovementState; - } - public void setLastMovementState(MovementState lastMovementState) { this.lastMovementState = lastMovementState; } @@ -5575,88 +3110,12 @@ public class PlayerCharacter extends AbstractCharacter { return characterHeight; } - public void setCharacterHeight(float characterHeight) { - this.characterHeight = characterHeight; - } - - public void setCenterHeight(float centerHeight) { - this.centerHeight = centerHeight; - } - public boolean isEnteredWorld() { return enteredWorld; } - public void setEnteredWorld(boolean enteredWorld) { - this.enteredWorld = enteredWorld; - } - - public long getChannelMute() { - return channelMute; - } - - public void setChannelMute(long channelMute) { - this.channelMute = channelMute; - } - - public boolean isLastSwimming() { - return lastSwimming; - } - - public boolean isTeleporting() { - return isTeleporting; - } - - public void setTeleporting(boolean isTeleporting) { - this.isTeleporting = isTeleporting; - } - - @Override - public final void teleport(final Vector3fImmutable targetLoc) { - - Regions targetRegion = Regions.GetRegionForTeleport(targetLoc); - locationLock.writeLock().lock(); - - try { - MovementManager.translocate(this, targetLoc, targetRegion); - } catch (Exception e) { - Logger.error(e); - } finally { - locationLock.writeLock().unlock(); - } - } - public ReadWriteLock getTeleportLock() { return teleportLock; } - public float getBargain() { - float bargain = 0; - - CharacterSkill bargainSkill = this.getSkills().get(engine.Enum.CharacterSkills.Bargaining.name()); - - if (bargainSkill != null) - bargain = bargainSkill.getModifiedAmountBeforeMods(); - - if (bargain > 100) - bargain = 100; - - bargain *= .01f; - - return bargain; - } - - public boolean isDirtyLoad() { - boolean dirtyValue; - dirtyLock.readLock().lock(); - dirtyValue = dirtyLoad; - dirtyLock.readLock().unlock(); - return dirtyValue; - } - - public void setDirtyLoad(boolean dirtyLoad) { - dirtyLock.writeLock().lock(); - this.dirtyLoad = dirtyLoad; - dirtyLock.writeLock().unlock(); - } } diff --git a/src/engine/objects/Portal.java b/src/engine/objects/Portal.java index f285f45a..68b6dac6 100644 --- a/src/engine/objects/Portal.java +++ b/src/engine/objects/Portal.java @@ -4,6 +4,7 @@ import engine.Enum; import engine.Enum.PortalType; import engine.InterestManagement.WorldGrid; import engine.gameManager.ConfigManager; +import engine.gameManager.PlayerManager; import engine.job.JobScheduler; import engine.jobs.CloseGateJob; import engine.math.Vector3fImmutable; @@ -104,7 +105,7 @@ public class Portal { if (player.getTimeStamp("lastMoveGate") < this.lastActive) return; - player.teleport(targetGate.getLoc()); + PlayerManager.teleport(player, targetGate.getLoc()); player.setSafeMode(); } diff --git a/src/engine/objects/Realm.java b/src/engine/objects/Realm.java index e97a4533..bc20b754 100644 --- a/src/engine/objects/Realm.java +++ b/src/engine/objects/Realm.java @@ -14,6 +14,7 @@ import engine.InterestManagement.RealmMap; import engine.db.archive.DataWarehouse; import engine.db.archive.RealmRecord; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.gameManager.PowersManager; import engine.net.ByteBufferWriter; import engine.powers.PowersBase; @@ -281,7 +282,7 @@ public class Realm { if (this.getRulingCity().getTOL() == null) return; - rulingCharacter = PlayerCharacter.getPlayerCharacter(this.getRulingCity().getTOL().getOwnerUUID()); + rulingCharacter = PlayerManager.getPlayerCharacter(this.getRulingCity().getTOL().getOwnerUUID()); if (rulingCharacter == null) { Logger.info(this.realmName + " failed to load " + this.getRulingCity().getCityName() + " ID : " + this.rulingCityUUID); return; diff --git a/src/engine/powers/effectmodifiers/NoModEffectModifier.java b/src/engine/powers/effectmodifiers/NoModEffectModifier.java index 7b80ac3e..20aca801 100644 --- a/src/engine/powers/effectmodifiers/NoModEffectModifier.java +++ b/src/engine/powers/effectmodifiers/NoModEffectModifier.java @@ -10,6 +10,7 @@ package engine.powers.effectmodifiers; import engine.Enum.GameObjectType; +import engine.gameManager.PlayerManager; import engine.jobs.AbstractEffectJob; import engine.objects.*; @@ -40,7 +41,7 @@ public class NoModEffectModifier extends AbstractEffectModifier { if (flyer.getAltitude() > 0) flyer.update(false); - PlayerCharacter.GroundPlayer(flyer); + PlayerManager.GroundPlayer(flyer); break; } diff --git a/src/engine/powers/poweractions/CharmPowerAction.java b/src/engine/powers/poweractions/CharmPowerAction.java index 100f5461..bec8f872 100644 --- a/src/engine/powers/poweractions/CharmPowerAction.java +++ b/src/engine/powers/poweractions/CharmPowerAction.java @@ -10,6 +10,7 @@ package engine.powers.poweractions; import engine.Enum; +import engine.gameManager.PlayerManager; import engine.math.Vector3fImmutable; import engine.net.client.ClientConnection; import engine.objects.AbstractCharacter; @@ -57,7 +58,7 @@ public class CharmPowerAction extends AbstractPowerAction { return; //turn mob into pet. - owner.commandSiegeMinion(mob); + PlayerManager.commandSiegeMinion(owner, mob); } @Override diff --git a/src/engine/powers/poweractions/RecallPowerAction.java b/src/engine/powers/poweractions/RecallPowerAction.java index c0ffb409..cadb251e 100644 --- a/src/engine/powers/poweractions/RecallPowerAction.java +++ b/src/engine/powers/poweractions/RecallPowerAction.java @@ -12,6 +12,7 @@ package engine.powers.poweractions; import engine.Enum.GameObjectType; import engine.InterestManagement.WorldGrid; import engine.gameManager.MovementManager; +import engine.gameManager.PlayerManager; import engine.math.Vector3fImmutable; import engine.net.Dispatch; import engine.net.DispatchMessage; @@ -45,7 +46,7 @@ public class RecallPowerAction extends AbstractPowerAction { PlayerCharacter pc = (PlayerCharacter) awo; - if (pc.hasBoon()) + if (PlayerManager.hasBoon(pc)) return; ClientConnection cc = pc.getClientConnection(); diff --git a/src/engine/powers/poweractions/RunegateTeleportPowerAction.java b/src/engine/powers/poweractions/RunegateTeleportPowerAction.java index 8f4753f1..37d59b55 100644 --- a/src/engine/powers/poweractions/RunegateTeleportPowerAction.java +++ b/src/engine/powers/poweractions/RunegateTeleportPowerAction.java @@ -10,6 +10,7 @@ package engine.powers.poweractions; import engine.Enum; +import engine.gameManager.PlayerManager; import engine.math.Vector3fImmutable; import engine.net.Dispatch; import engine.net.DispatchMessage; @@ -22,7 +23,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import static engine.math.FastMath.sqr; -import static engine.math.FastMath.sqrt; public class RunegateTeleportPowerAction extends AbstractPowerAction { @@ -65,7 +65,7 @@ public class RunegateTeleportPowerAction extends AbstractPowerAction { } else { if (rg != null) { - pc.teleport(rg.getLoc()); + PlayerManager.teleport(pc, rg.getLoc()); pc.setSafeMode(); } } diff --git a/src/engine/server/login/LoginServer.java b/src/engine/server/login/LoginServer.java index 2ad411bb..c79b8811 100644 --- a/src/engine/server/login/LoginServer.java +++ b/src/engine/server/login/LoginServer.java @@ -460,7 +460,7 @@ public class LoginServer { case "character": DbManager.removeFromCache(Enum.GameObjectType.PlayerCharacter, objectUUID); PlayerCharacter player = (PlayerCharacter) DbManager.getObject(Enum.GameObjectType.PlayerCharacter, objectUUID); - PlayerCharacter.initializePlayer(player); + PlayerManager.initializePlayer(player); player.getAccount().characterMap.replace(player.getObjectUUID(), player); Logger.info("Player active state is : " + player.isActive()); break; diff --git a/src/engine/server/login/LoginServerMsgHandler.java b/src/engine/server/login/LoginServerMsgHandler.java index dff76ce7..288431f1 100644 --- a/src/engine/server/login/LoginServerMsgHandler.java +++ b/src/engine/server/login/LoginServerMsgHandler.java @@ -14,6 +14,7 @@ import engine.Enum.DispatchChannel; import engine.Enum.GameObjectType; import engine.gameManager.ConfigManager; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.gameManager.SessionManager; import engine.job.JobScheduler; import engine.jobs.DisconnectJob; @@ -346,7 +347,7 @@ public class LoginServerMsgHandler implements NetMsgHandler { return; } - PlayerCharacter pc = PlayerCharacter.generatePCFromCommitNewCharacterMsg(session.getAccount(), commitNewCharacterMessage, clientConnection); + PlayerCharacter pc = PlayerManager.generatePCFromCommitNewCharacterMsg(session.getAccount(), commitNewCharacterMessage, clientConnection); if (pc == null) { Logger.info("Player returned null while creating character."); @@ -354,7 +355,7 @@ public class LoginServerMsgHandler implements NetMsgHandler { return; } - PlayerCharacter.initializePlayer(pc); + PlayerManager.initializePlayer(pc); session.getAccount().characterMap.putIfAbsent(pc.getObjectUUID(), pc); // Send back to Character Select Screen this.sendCharacterSelectScreen(session, true); @@ -372,7 +373,7 @@ public class LoginServerMsgHandler implements NetMsgHandler { Session session; session = SessionManager.getSession(origin); - playerCharacter = PlayerCharacter.getPlayerCharacter(msg.getCharacterUUID()); + playerCharacter = PlayerManager.getPlayerCharacter(msg.getCharacterUUID()); if (playerCharacter == null) { Logger.error("Delete Error: PlayerID=" + msg.getCharacterUUID() + " not found."); diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 30935c20..956b336d 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -744,7 +744,7 @@ public class WorldServer { DispatchMessage.dispatchMsgToInterestArea(playerCharacter, updateStateMsg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); if (playerCharacter.region != null) - if (PlayerCharacter.CanBindToBuilding(playerCharacter, playerCharacter.region.parentBuildingID)) + if (PlayerManager.CanBindToBuilding(playerCharacter, playerCharacter.region.parentBuildingID)) playerCharacter.bindBuilding = playerCharacter.region.parentBuildingID; else playerCharacter.bindBuilding = 0; @@ -775,7 +775,7 @@ public class WorldServer { loadedMob.playerAgroMap.remove(player.getObjectUUID()); } player.getTimestamps().put("logout", System.currentTimeMillis()); - player.setEnteredWorld(false); + PlayerManager.setEnteredWorld(player, false); // remove from simulation and zero current loc @@ -809,7 +809,7 @@ public class WorldServer { player.respawnLock.writeLock().lock(); try { if (!player.isAlive()) - player.respawn(false, false, true); + PlayerManager.respawn(player, false, false, true); } catch (Exception e) { Logger.error(e); } finally { diff --git a/src/engine/session/CSSession.java b/src/engine/session/CSSession.java index 675f394c..dc4d8ab1 100644 --- a/src/engine/session/CSSession.java +++ b/src/engine/session/CSSession.java @@ -10,6 +10,7 @@ package engine.session; import engine.gameManager.DbManager; +import engine.gameManager.PlayerManager; import engine.objects.AbstractGameObject; import engine.objects.Account; import engine.objects.PlayerCharacter; @@ -34,7 +35,7 @@ public class CSSession extends AbstractGameObject { this.machineID = machineID; if (this.playerCharacter != null) - PlayerCharacter.initializePlayer(this.playerCharacter); + PlayerManager.initializePlayer(this.playerCharacter); } /* diff --git a/src/engine/workthreads/HalfHourlyJobThread.java b/src/engine/workthreads/HalfHourlyJobThread.java index 084719e9..0a43bcf1 100644 --- a/src/engine/workthreads/HalfHourlyJobThread.java +++ b/src/engine/workthreads/HalfHourlyJobThread.java @@ -15,19 +15,12 @@ import engine.db.archive.DataWarehouse; import engine.db.archive.MineRecord; import engine.gameManager.*; import engine.net.DispatchMessage; -import engine.net.MessageDispatcher; import engine.net.client.msg.chat.ChatSystemMsg; import engine.objects.*; -import engine.server.world.WorldServer; import org.pmw.tinylog.Logger; import java.time.LocalDateTime; import java.util.ArrayList; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ThreadLocalRandom; - -import static engine.gameManager.StrongholdManager.EndStronghold; -import static engine.server.MBServerStatics.MINE_LATE_WINDOW; public class HalfHourlyJobThread implements Runnable { @@ -155,7 +148,7 @@ public class HalfHourlyJobThread implements Runnable { mine.setActive(false); mine.wasClaimed = true; for(Integer id : mine._playerMemory){ - PlayerCharacter pc = PlayerCharacter.getFromCache(id); + PlayerCharacter pc = PlayerManager.getFromCache(id); if(pc != null) pc.ZergMultiplier = 1.0f; }